Skip to content

Commit

Permalink
Standardize flag parsing (#1431)
Browse files Browse the repository at this point in the history
* Standardize flag parsing
  • Loading branch information
joel-rieke authored Jan 16, 2025
1 parent 0bd4b83 commit 701b6cb
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions atrium/vestibulum/trcshbase/trcsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,15 @@ func CommonMain(envPtr *string, addrPtr *string, envCtxPtr *string,
eUtils.InitHeadless(true)
var regionPtr, trcPathPtr, projectServicePtr *string
var dronePtr *bool
var projectServiceFlagPtr *string
var droneFlagPtr *bool
// Initiate signal handling.
var ic chan os.Signal = make(chan os.Signal, 5)

regionPtr = flagset.String("region", "", "Region to be processed") //If this is blank -> use context otherwise override context.
trcPathPtr = flagset.String("c", "", "Optional script to execute.") //If this is blank -> use context otherwise override context.

if kernelopts.BuildOptions.IsKernel() {
dronePtr = new(bool)
*dronePtr = true
} else {
dronePtr = flagset.Bool("drone", false, "Run as drone.")
}
projectServiceFlagPtr = flagset.String("projectService", "", "Service namespace to pull templates from if not present in LFS")
droneFlagPtr = flagset.Bool("drone", false, "Run as drone.")

// Initialize the token cache
gTokenCache = cache.NewTokenCacheEmpty()
Expand All @@ -332,7 +329,6 @@ func CommonMain(envPtr *string, addrPtr *string, envCtxPtr *string,
os.Args[1] = "-c=" + os.Args[1]
}
}
projectServicePtr = flagset.String("projectService", "", "Service namespace to pull templates from if not present in LFS")
signal.Notify(ic, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP, syscall.SIGABRT)
} else {
dronePtr = new(bool)
Expand All @@ -347,6 +343,16 @@ func CommonMain(envPtr *string, addrPtr *string, envCtxPtr *string,

flagset.Parse(argLines[1:])

if kernelopts.BuildOptions.IsKernel() {
dronePtr = new(bool)
*dronePtr = true
} else {
if dronePtr == nil || !*dronePtr {
dronePtr = droneFlagPtr
}
}
projectServicePtr = projectServiceFlagPtr

if !*dronePtr {
if len(*appRoleIDPtr) == 0 {
*appRoleIDPtr = os.Getenv("DEPLOY_ROLE")
Expand Down

0 comments on commit 701b6cb

Please sign in to comment.