Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions cmd/bedrock_helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ func reportArgumentParsingError(format string, args ...any) {
fmt.Fprintf(os.Stderr, fullFormat, args...)
}

// hasArgument checks if a specific argument exists in the raw command-line arguments.
// The function also automatically checks with the `-` and `--` prefixes.
// For example, hasArgument("version") returns true when `--version` is one of the arguments.
// Returns true when the given value is found. Returns false otherwise.
func hasArgument(value string) bool {
// Loop through arguments, skipping the first one (program path)
for _, arg := range os.Args[1:] {
// Specific value
if arg == value {
// Found exact match
return true
}

// Try the `-` and `--` prefixes
if arg == "--"+value || arg == "-"+value {
// Found exact match
return true
}
}
return false
}

// newBedrockFlagSet initializes the FlagSet and binds fields directly to the Config struct
func newBedrockFlagSet(cfg *Config) *flag.FlagSet {
fs := flag.NewFlagSet("bedrock_helper", flag.ContinueOnError)
Expand Down Expand Up @@ -234,8 +256,8 @@ func run(args []string) int {
// Manually parse for `--no-header` and `--version` arguments before calling fs.Parse().
// In case of parsing errors, the error will be printed before the flag library will call our custom fs.Usage().
// So we must print the application's header or version before doing the actual parsing.
cfg.NoHeader = *flag.Bool("no-header", false, "") // hasArgument("--no-header")
cfg.Version = *flag.Bool("version", false, "") // hasArgument("--version")
cfg.NoHeader = hasArgument("no-header")
cfg.Version = hasArgument("version")

// Should we only print the version ?
if cfg.Version {
Expand Down