Documentation
¶
Overview ¶
Package legacy holds the pre-cobra (urfave → cobra) migration compatibility shims for the bitrise CLI: legacy argument normalization, dispatch parsing and the hand-rolled flag/env "mode" resolution. They are isolated here, away from the command wiring in package cli, so the compatibility surface is easy to spot and the next major version can drop the package wholesale. It depends only on cobra/pflag and the configs package — never on cli.
Index ¶
- func ApplyGlobalFlagsFromArgs(root *cobra.Command, args []string, globalFlagNames []string)
- func CIModeFlagOverride(cmd *cobra.Command, ciFlagName string) *bool
- func CommandTokenIndex(args []string, globalFlagNames []string) int
- func EnableUnknownFlagPassthrough(cmd *cobra.Command)
- func IsDebugMode(arguments []string, debugFlagName string) bool
- func IsFlag(name, arg string) bool
- func IsKnownCommand(root *cobra.Command, name string) bool
- func NormalizeLegacyArgs(args []string, root *cobra.Command) []string
- func PRModeFlagOverride(cmd *cobra.Command, prFlagName string) *bool
- func RunSecretFilteringOverride(cmd *cobra.Command, flagName string) *bool
- func SecretEnvsFilteringOverride() *bool
- func SecretFilteringFlagOverride(cmd *cobra.Command, flagName string) (*bool, error)
- func ValidateGlobalBoolEnvs() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyGlobalFlagsFromArgs ¶
ApplyGlobalFlagsFromArgs sets the global flags on the plugin/envman dispatch paths, where cobra does not parse them. Only the leading args (before the command token) are bitrise globals; anything after belongs to the passthrough.
func CIModeFlagOverride ¶
CIModeFlagOverride resolves the --ci flag bound to the CI env var: the flag value if passed, otherwise the parsed env value if present, otherwise nil.
func CommandTokenIndex ¶
CommandTokenIndex returns the index of the first argument that is not a global flag — the command/plugin/positional token. Global flags before this boundary configure bitrise; everything from it onward belongs to the command (and, for plugins and envman, is forwarded verbatim), so it must not be scanned for or stripped of global flags.
func EnableUnknownFlagPassthrough ¶
EnableUnknownFlagPassthrough sets FParseErrWhitelist.UnknownFlags on the whole command tree. urfave/cli left an unrecognised flag that followed a positional argument in the argument list and ignored it (e.g. `bitrise run wf --unknown` still ran the workflow); pflag rejects unknown flags outright. The flag is per-command (cobra does not inherit it), and the command that ultimately runs is the one that parses, so it must be set on every command, not just the root. The next major version, which reworks the command surface, can tighten this.
func IsDebugMode ¶
IsDebugMode resolves debug mode before cobra parses the command line, so the logger can be configured up front. An explicit truthy --debug enables it; otherwise the bound DEBUG env var decides, so a set DEBUG=true still enables debug mode even alongside an explicit --debug=false.
TODO: MIGRATION PERIOD - NEEDED TO KEEP COMPATIBILITY The correct precedence is "explicit flag wins" (matching --ci/--pr), but the pre-cobra CLI let a set DEBUG=true env override an explicit --debug=false (loggerParameters resolved the flag, then fell through to the env unless the flag was truthy). Reproduced here so debug mode toggles identically; the next major can make the flag win.
The arg scan is intentionally unbounded (no command-token boundary), so a plugin's or envman's own trailing --debug also toggles this early logger — again matching the pre-cobra CLI. See debugFlagFromArgs.
func NormalizeLegacyArgs ¶
NormalizeLegacyArgs rewrites single-dash long flags (e.g. `-config`) to their double-dash form, so both spellings are accepted: urfave/Go-flag took `-config` ≡ `--config`, but pflag accepts only `--config` / `-c`. The next major can drop this (with its normalizeArg / knownLongFlagNames helpers) and accept only the double-dash form. Passthrough args are left untouched: everything after `--` and everything from the envman command onwards (envman forwards its args verbatim and uses single-dash long flags of its own).
func PRModeFlagOverride ¶
PRModeFlagOverride resolves the --pr flag. Unlike CI, the PR env vars (PR mode and pull request ID) are interpreted by isPRMode together with the inventory, so only the flag is resolved here.
func RunSecretFilteringOverride ¶
RunSecretFilteringOverride resolves run's --secret-filtering flag, which (unlike trigger's) was never bound to the BITRISE_SECRET_FILTERING env var: the flag value if passed, otherwise the env matched literally, otherwise nil. A non-bool env value is ignored (not aborted), matching the pre-cobra behaviour.
func SecretEnvsFilteringOverride ¶
func SecretEnvsFilteringOverride() *bool
SecretEnvsFilteringOverride resolves the secret-envs-filtering mode, which has no flag and was never env-bound: the env matched literally, otherwise nil so detection falls back to the inventory.
func SecretFilteringFlagOverride ¶
SecretFilteringFlagOverride resolves trigger's --secret-filtering flag, which was bound to the BITRISE_SECRET_FILTERING env var: the flag value if passed, otherwise the parsed env value if present (an empty value is treated as false), otherwise nil. A non-bool env value returns an error, matching the previous framework's abort. run's flag was not env-bound — see RunSecretFilteringOverride.
func ValidateGlobalBoolEnvs ¶
func ValidateGlobalBoolEnvs() error
ValidateGlobalBoolEnvs returns an error when a global bool flag's bound environment variable holds a non-bool value, matching the behaviour of the previous framework (an empty value is allowed and treated as false).
Types ¶
This section is empty.