You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2022/07/18 18:00:01 UTC

[GitHub] [trafficcontrol] rob05c commented on a diff in pull request #6962: t3c to look for t3c-generate and other t3c- apps in executable directory

rob05c commented on code in PR #6962:
URL: https://github.com/apache/trafficcontrol/pull/6962#discussion_r923645628


##########
cache-config/t3cutil/t3cutil.go:
##########
@@ -228,3 +232,14 @@ func UserAgentStr(appName string, versionNum string, gitRevision string) string
 	}
 	return appName + "/" + versionNum + ".." + gitRevision
 }
+
+// InstallDirectory returns the location of the executable directory.
+// If error, returns "/usr/bin" as default.
+func InstallDirectory() string {
+	installdir, err := osext.ExecutableFolder()
+	if err != nil {
+		installdir = "/usr/bin"

Review Comment:
   Mind putting this in a global const? Just so it's easier to see, change, etc.



##########
cache-config/t3cutil/t3cutil.go:
##########
@@ -228,3 +232,14 @@ func UserAgentStr(appName string, versionNum string, gitRevision string) string
 	}
 	return appName + "/" + versionNum + ".." + gitRevision
 }
+
+// InstallDirectory returns the location of the executable directory.
+// If error, returns "/usr/bin" as default.
+func InstallDirectory() string {

Review Comment:
   Would you object to naming this `InstallDir` instead? Kind of a nitpick, but it's a slightly bigger deal because of how frequently this is used. 
   
   Idiomatic Go prefers shorter names. Personally, I like to use the shortest abbreviation that's obvious and unambiguous. But I don't feel _that_ strongly about it, if you disagree.



##########
cache-config/t3c-apply/torequest/cmd.go:
##########
@@ -85,7 +86,8 @@ func generate(cfg config.Cfg) ([]t3cutil.ATSConfigFile, error) {
 	args = append(args, "--disable-parent-config-comments="+strconv.FormatBool(cfg.DisableParentConfigComments))
 	args = append(args, "--use-strategies="+cfg.UseStrategies.String())
 
-	generatedFiles, stdErr, code := t3cutil.DoInput(configData, config.GenerateCmd, args...)
+	genpath := filepath.Join(t3cutil.InstallDirectory(), config.GenerateCmd)

Review Comment:
   So, this is used in a bunch of places, basically every sub-app call.
   
   If you changed them all to use the `t3c` wrapper, e.g. `t3c generate` instead of `t3c-generate`, you could avoid all the duplication, put this in a global var, `var t3cPath = filepath.Join(t3cutil.InstallDir() + "t3c")`, and then all the args would just start with the sub-app, e.g.
   ```
   args := []string{"preprocess"}
   args += ...
   cmd := exec.Command(t3cPath, args...)
   ```



##########
cache-config/t3cutil/t3cutil.go:
##########
@@ -228,3 +232,14 @@ func UserAgentStr(appName string, versionNum string, gitRevision string) string
 	}
 	return appName + "/" + versionNum + ".." + gitRevision
 }
+
+// InstallDirectory returns the location of the executable directory.
+// If error, returns "/usr/bin" as default.
+func InstallDirectory() string {
+	installdir, err := osext.ExecutableFolder()

Review Comment:
   ATC is on Go >1.18 which has `os.Executable()`. Can you change this to `os.Executable`, and not use/vendor `osext`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org