Skip to content
Merged
Show file tree
Hide file tree
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
36 changes: 29 additions & 7 deletions cmd/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ exit code of "devsy ci".`,
}

func (cmd *CICmd) registerFlags(ciCmd *cobra.Command) {
cmd.registerRunFlags(ciCmd)
cmd.registerBuildFlags(ciCmd)
cmd.registerWorkspaceFlags(ciCmd)
cmd.registerSecretsFlags(ciCmd)
}

func (cmd *CICmd) registerRunFlags(ciCmd *cobra.Command) {
cliflags.Add(ciCmd,
cliflags.String(&cmd.RunCmdString, runCmdFlag, "",
"Shell command to run inside the container, executed via sh -c "+
Expand All @@ -75,14 +82,15 @@ func (cmd *CICmd) registerFlags(ciCmd *cobra.Command) {
"Environment variables to set in the container at run time (KEY=VALUE, repeatable)"),
cliflags.Bool(&cmd.Keep, keepFlag, false,
"Keep the workspace after running instead of tearing it down (useful for debugging)"),
)
}

func (cmd *CICmd) registerBuildFlags(ciCmd *cobra.Command) {
cliflags.Add(ciCmd,
cliflags.String(&cmd.DevContainerSource, names.DevContainer, "",
"Select the devcontainer config source, overriding project discovery: "+
`"none" (ignore the project config), "image:<ref>" (use only that image), `+
`"id:<name>" (a named .devcontainer/<name> profile), or a path to a devcontainer.json`),
cliflags.StringSlice(&cmd.ProviderOptions, names.ProviderOption, nil,
"Provider option in the form KEY=VALUE"),
cliflags.String(&cmd.Machine, names.Machine, "",
"The machine to use for this workspace. The machine needs to exist beforehand"),
cliflags.Bool(&cmd.NoCache, names.NoCache, false,
"Do not use the build cache when building the image"),
cliflags.String(&cmd.RunPlatform, names.Platform, "",
Expand All @@ -95,6 +103,18 @@ func (cmd *CICmd) registerFlags(ciCmd *cobra.Command) {
cliflags.StringArray(&cmd.CacheFrom, names.CacheFrom, nil,
"Cache sources for the build (e.g., myregistry.io/cache:latest). "+
"Reuse a pre-built image to warm the build"),
)
cliflags.RegisterDevContainerModifierFlags(ciCmd.Flags(), cliflags.DevContainerModifierFlags{
Features: &cmd.AdditionalFeatures,
})
}

func (cmd *CICmd) registerWorkspaceFlags(ciCmd *cobra.Command) {
cliflags.Add(ciCmd,
cliflags.StringSlice(&cmd.ProviderOptions, names.ProviderOption, nil,
"Provider option in the form KEY=VALUE"),
cliflags.String(&cmd.Machine, names.Machine, "",
"The machine to use for this workspace. The machine needs to exist beforehand"),
cliflags.StringArray(&cmd.WorkspaceEnv, names.WorkspaceEnv, nil,
"Env variables available at build/lifecycle time (KEY=VALUE, repeatable)"),
cliflags.StringSlice(&cmd.WorkspaceEnvFile, names.WorkspaceEnvFile, nil,
Expand All @@ -105,6 +125,11 @@ func (cmd *CICmd) registerFlags(ciCmd *cobra.Command) {
nil,
"Extra env variables to inject during workspace initialization (KEY=VALUE, repeatable)",
),
)
}

func (cmd *CICmd) registerSecretsFlags(ciCmd *cobra.Command) {
cliflags.Add(ciCmd,
cliflags.String(
&cmd.SecretsFile,
names.SecretsFile,
Expand All @@ -127,9 +152,6 @@ func (cmd *CICmd) registerFlags(ciCmd *cobra.Command) {
cliflags.String(&cmd.GitTokenUsername, names.GitTokenUsername, "",
"Username for --git-token (default inferred from the repo host)"),
)
cliflags.RegisterDevContainerModifierFlags(ciCmd.Flags(), cliflags.DevContainerModifierFlags{
Features: &cmd.AdditionalFeatures,
})
}

func splitArgs(
Expand Down
36 changes: 27 additions & 9 deletions cmd/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,32 @@ type GlobalFlags struct {
func SetGlobalFlags(flags *flag.FlagSet) *GlobalFlags {
globalFlags := &GlobalFlags{}

registerCoreFlags(flags, globalFlags)
registerOutputFlags(flags, globalFlags)
registerVerbosityFlags(flags, globalFlags)
registerHiddenFlags(flags, globalFlags)
bindGlobalEnvVars(flags)

return globalFlags
}

func registerCoreFlags(flags *flag.FlagSet, globalFlags *GlobalFlags) {
flags.StringVar(
&globalFlags.DevsyHome,
names.Home,
"",
"If defined will override the default devsy home",
)
flags.StringVar(&globalFlags.Context, names.Context, "", "The context to use")
flags.StringVar(
&globalFlags.Provider,
names.Provider,
"",
"The provider to use. Needs to be configured for the selected context",
)
}

func registerOutputFlags(flags *flag.FlagSet, globalFlags *GlobalFlags) {
flags.StringVar(
&globalFlags.ResultFormat,
names.ResultFormat,
Expand All @@ -46,13 +66,9 @@ func SetGlobalFlags(flags *flag.FlagSet) *GlobalFlags {
)
flags.StringVar(&globalFlags.LogOutput, names.LogFormat, "text", "Alias for --log-output")
_ = flags.MarkHidden(names.LogFormat)
flags.StringVar(&globalFlags.Context, names.Context, "", "The context to use")
flags.StringVar(
&globalFlags.Provider,
names.Provider,
"",
"The provider to use. Needs to be configured for the selected context",
)
}

func registerVerbosityFlags(flags *flag.FlagSet, globalFlags *GlobalFlags) {
flags.CountVarP(
&globalFlags.Verbosity,
names.Verbose,
Expand All @@ -72,7 +88,9 @@ func SetGlobalFlags(flags *flag.FlagSet) *GlobalFlags {
false,
"Enable debug logging (equivalent to -vv)",
)
}

func registerHiddenFlags(flags *flag.FlagSet, globalFlags *GlobalFlags) {
flags.Var(&globalFlags.Owner, names.Owner, "Show pro workspaces for owner")
_ = flags.MarkHidden(names.Owner)
flags.StringVar(&globalFlags.UID, names.UID, "", "Set UID for workspace")
Expand All @@ -84,11 +102,11 @@ func SetGlobalFlags(flags *flag.FlagSet) *GlobalFlags {
"The data folder where agent data is stored.",
)
_ = flags.MarkHidden(names.AgentDir)
}

func bindGlobalEnvVars(flags *flag.FlagSet) {
pkgflags.BindEnv(flags, names.Home)
pkgflags.BindEnv(flags, names.Context)
pkgflags.BindEnv(flags, names.Provider)
pkgflags.BindEnv(flags, names.Debug)

return globalFlags
}
Loading
Loading