Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3501 from hashicorp/feat/cli-docs/include-default…
Browse files Browse the repository at this point in the history
…-flag-value

internal/cli: Include default value for a flag for docs
  • Loading branch information
briancain authored Jun 28, 2022
2 parents 553fbac + 1f3b701 commit bfe7c7b
Show file tree
Hide file tree
Showing 96 changed files with 390 additions and 359 deletions.
18 changes: 15 additions & 3 deletions internal/cli/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,25 @@ description: "%s"
}
}

str := fmt.Sprintf("- `-%s` - %s", name, f.Usage)
if len(f.Aliases) > 0 {
aliases := strings.Join(f.Aliases, "`, `-")

fmt.Fprintf(w, "- `-%s` (`-%s`) - %s\n", name, aliases, f.Usage)
} else {
fmt.Fprintf(w, "- `-%s` - %s\n", name, f.Usage)
str = fmt.Sprintf("- `-%s` (`-%s`) - %s", name, aliases, f.Usage)
}

// Add a period at the end of the doc sentence if the field didn't add
// one already.
if !strings.HasSuffix(str, ".") {
str += "."
}

if f.Default != "" {
str = fmt.Sprintf("%s The default is %s.", str, f.Default)
}
str += "\n"

fmt.Fprint(w, str)
})
})
} else {
Expand Down
13 changes: 9 additions & 4 deletions internal/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ func (c *InstallCommand) Run(args []string) int {
callOpts = append(callOpts, grpc.PerRPCCredentials(
serverclient.StaticToken(contextConfig.Server.AuthToken)))

// This is our default, so let's actually set the timestamp if not set on the CLI
if c.contextName == "" {
c.contextName = fmt.Sprintf("install-%d", time.Now().Unix())
}

// If we connected successfully, lets immediately setup our context.
if c.contextName != "" {
if err := c.contextStorage.Set(c.contextName, contextConfig); err != nil {
Expand Down Expand Up @@ -357,11 +362,11 @@ func (c *InstallCommand) Flags() *flag.Sets {
})

f.StringVar(&flag.StringVar{
Name: "context-create",
Target: &c.contextName,
Default: fmt.Sprintf("install-%d", time.Now().Unix()),
Name: "context-create",
Target: &c.contextName,
Usage: "Create a context with connection information for this installation. " +
"The default value will be suffixed with a timestamp at the time the command is executed.",
"The default value if not set will be 'install-' and then be suffixed with a " +
"timestamp at the time the command is executed.",
})

f.BoolVar(&flag.BoolVar{
Expand Down
13 changes: 11 additions & 2 deletions internal/cli/runner_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func (c *RunnerAgentCommand) Run(args []string) int {
plugin.InsideODR = c.flagODR

// Flag defaults
if c.flagConcurrency == 0 {
c.flagConcurrency = runtime.NumCPU() * 3
}

// Check again in case it was set to 0.
if c.flagConcurrency < 1 {
log.Warn("concurrency flag less than 1 has no effect, using 1")
c.flagConcurrency = 1
Expand Down Expand Up @@ -366,12 +371,16 @@ func (c *RunnerAgentCommand) Flags() *flag.Sets {
Name: "concurrency",
Target: &c.flagConcurrency,
Usage: "The number of concurrent jobs that can be running at one time. " +
"This has no effect if `-odr` is set. A value of less than 1 will " +
"This has no effect if `-odr` is set. The default value applied will be " +
"(total number of logical cpus available * 3). A value of less than 1 will " +
"default to 1.",

// Most jobs that a non-ODR runner runs are IO bound, so we use
// just a heuristic here of allowing some multiple above the CPUs.
Default: runtime.NumCPU() * 3,
//Default: runtime.NumCPU() * 3,
// NOTE(briancain): We set a default of 0 here, but when the CLI goes
// to use this value, if set to 0, we'll attempt to set it to the default
// runtime.NumCPU()*3.
})
})
}
Expand Down
7 changes: 6 additions & 1 deletion internal/cli/server_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ func (c *ServerBootstrapCommand) Run(args []string) int {

// If we aren't storing a context, we're done
if c.flagContext == "" {
// NOTE(briancain): I don't think this will ever happen unless the user
// specifically sets the flag to empty string. Our flag package will set
// the default here, which will never be emptry string
return 0
} else if c.flagContext == "bootstrap-timestamp" {
c.flagContext = fmt.Sprintf("bootstrap-%d", time.Now().Unix())
}

// Get our current context config and set our new token
Expand Down Expand Up @@ -100,7 +105,7 @@ func (c *ServerBootstrapCommand) Flags() *flag.Sets {
Usage: "Create a CLI context for this bootstrapped server. The context name " +
"will be the value of this flag. If this is an empty string, a context will " +
"not be created",
Default: fmt.Sprintf("bootstrap-%d", time.Now().Unix()),
Default: "bootstrap-timestamp",
})

f.BoolVar(&flag.BoolVar{
Expand Down
4 changes: 2 additions & 2 deletions website/content/commands/artifact-build.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Build a new versioned artifact from source.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.
Expand All @@ -40,6 +40,6 @@ Build a new versioned artifact from source.

#### Command Options

- `-push` - Push the artifact to the configured registry.
- `-push` - Push the artifact to the configured registry. The default is true.

@include "commands/artifact-build_more.mdx"
6 changes: 3 additions & 3 deletions website/content/commands/artifact-list-builds.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ expected to be stored in a registry.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.

#### Command Options

- `-workspace-all` - List builds in all workspaces for this project and application.
- `-long-ids` - Show long identifiers rather than sequence numbers.
- `-workspace-all` - List builds in all workspaces for this project and application. The default is false.
- `-long-ids` - Show long identifiers rather than sequence numbers. The default is false.

@include "commands/artifact-list-builds_more.mdx"
12 changes: 6 additions & 6 deletions website/content/commands/artifact-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ list the artifacts that are just part of local builds.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.

#### Command Options

- `-workspace-all` - List builds in all workspaces for this project and application.
- `-verbose` (`-V`) - Display more details about each deployment.
- `-json` - Output the deployment information as JSON.
- `-long-ids` - Show long identifiers rather than sequence numbers.
- `-workspace-all` - List builds in all workspaces for this project and application. The default is false.
- `-verbose` (`-V`) - Display more details about each deployment. The default is false.
- `-json` - Output the deployment information as JSON. The default is false.
- `-long-ids` - Show long identifiers rather than sequence numbers. The default is false.

#### Filter Options

- `-order-by=<string>` - Order the values by which field. One possible value from: start-time, complete-time.
- `-desc` - Sort the values in descending order.
- `-desc` - Sort the values in descending order. The default is false.
- `-limit=<uint>` - How many values to show.

@include "commands/artifact-list_more.mdx"
2 changes: 1 addition & 1 deletion website/content/commands/artifact-push.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ local builds using "artifact list-builds" command.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.
Expand Down
2 changes: 1 addition & 1 deletion website/content/commands/auth-method-delete.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Usage: `waypoint auth-method delete NAME`

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.
Expand Down
2 changes: 1 addition & 1 deletion website/content/commands/auth-method-inspect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Usage: `waypoint auth-method inspect NAME`

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.
Expand Down
2 changes: 1 addition & 1 deletion website/content/commands/auth-method-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Usage: `waypoint auth-method list`

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.
Expand Down
4 changes: 2 additions & 2 deletions website/content/commands/auth-method-set-oidc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Configure an OIDC auth method.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.
Expand All @@ -41,7 +41,7 @@ Configure an OIDC auth method.
- `-issuer=<string>` - Discovery URL of the OIDC provider that implements the .well-known/openid-configuration metadata endpoint.
- `-issuer-ca-pem=<string>` - PEM-encoded certificates for connecting to the issuer. May be specified multiple times.
- `-allowed-redirect-uri=<string>` - Allowed URI for auth redirection. This automatically has localhost (for CLI auth) and the server address configured. If you have additional external addresses, you can specify them here. May be specified multiple times.
- `-claim-mapping=<key=value>` - Mapping of a claim to a variable value for the access selector. This can be specified multiple times. Example value: 'http://example.com/key=key'
- `-claim-mapping=<key=value>` - Mapping of a claim to a variable value for the access selector. This can be specified multiple times. Example value: 'http://example.com/key=key'.
- `-list-claim-mapping=<key=value>` - Same as claim-mapping but for list values. This can be repeated multiple times.

@include "commands/auth-method-set-oidc_more.mdx"
4 changes: 2 additions & 2 deletions website/content/commands/build.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Build a new versioned artifact from source.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.
Expand All @@ -40,6 +40,6 @@ Build a new versioned artifact from source.

#### Command Options

- `-push` - Push the artifact to the configured registry.
- `-push` - Push the artifact to the configured registry. The default is true.

@include "commands/build_more.mdx"
8 changes: 4 additions & 4 deletions website/content/commands/config-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ as well.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.

#### Command Options

- `-json` - Output in JSON
- `-raw` - Output in key=val
- `-runner` - Show configuration that is set on runners. This will not show any configuration that is set on any applications. This only includes configuration set with the -runner flag.
- `-json` - Output in JSON. The default is false.
- `-raw` - Output in key=val. The default is false.
- `-runner` - Show configuration that is set on runners. This will not show any configuration that is set on any applications. This only includes configuration set with the -runner flag. The default is false.
- `-label=<key=value>` - Labels to set for this operation. Can be specified multiple times.

@include "commands/config-get_more.mdx"
6 changes: 3 additions & 3 deletions website/content/commands/config-set.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ Specify the "-app" flag to set a config variable for a specific app.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.

#### Command Options

- `-scope=<string>` - The scope for this configuration. The configuration will only appear within this scope. This can be one of 'global', 'project', or 'app'.
- `-scope=<string>` - The scope for this configuration. The configuration will only appear within this scope. This can be one of 'global', 'project', or 'app'. The default is project.
- `-workspace-scope=<string>` - Specify that the configuration is only available within a specific workspace. This configuration will only be set for deployments or operations (if -runner if set) when the workspace matches this.
- `-label-scope=<string>` - If set, configuration will only be set if the deployment or operation (if -runner is set) has a matching label set.
- `-runner` - Expose this configuration on runners. This can be used to set things such as credentials to cloud platforms for remote runners. This configuration will not be exposed to deployed applications. If this is specified in the context of a project, this will apply only to runners operating on jobs for the specific project or application.
- `-runner` - Expose this configuration on runners. This can be used to set things such as credentials to cloud platforms for remote runners. This configuration will not be exposed to deployed applications. If this is specified in the context of a project, this will apply only to runners operating on jobs for the specific project or application. The default is false.

@include "commands/config-set_more.mdx"
2 changes: 1 addition & 1 deletion website/content/commands/config-source-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To use this command, you must specify a "-type" flag.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.
Expand Down
4 changes: 2 additions & 2 deletions website/content/commands/config-source-set.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ you're configuring for details on what configuration fields are available.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.
Expand All @@ -39,6 +39,6 @@ you're configuring for details on what configuration fields are available.

- `-type=<string>` - Dynamic source type to configure, such as 'vault'.
- `-config=<key=value>` - Configuration for the dynamic source type. This may be repeated. The fields available are dependent on the dynamic source type, so please check the documentation for that specific type for more information.
- `-delete` - Delete the configuration for this source type. If this is set then the -config flag is ignored.
- `-delete` - Delete the configuration for this source type. If this is set then the -config flag is ignored. The default is false.

@include "commands/config-source-set_more.mdx"
2 changes: 1 addition & 1 deletion website/content/commands/config-sync.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ be deleted.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.
Expand Down
2 changes: 1 addition & 1 deletion website/content/commands/context-clear.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ the project.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.
Expand Down
12 changes: 6 additions & 6 deletions website/content/commands/context-create.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ Creates a new context.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.

#### Command Options

- `-set-default` - Set this context as the new default for the CLI.
- `-set-default` - Set this context as the new default for the CLI. The default is true.
- `-server-addr=<string>` - Address for the server.
- `-server-auth-token=<string>` - Authentication token to use to connect to the server.
- `-server-platform=<string>` - The current platform that Waypoint server is running on.
- `-server-tls` - If true, will connect to the server over TLS.
- `-server-tls-skip-verify` - If true, will not validate TLS cert presented by the server.
- `-server-require-auth` - If true, will send authentication details.
- `-server-platform=<string>` - The current platform that Waypoint server is running on. The default is n/a.
- `-server-tls` - If true, will connect to the server over TLS. The default is true.
- `-server-tls-skip-verify` - If true, will not validate TLS cert presented by the server. The default is false.
- `-server-require-auth` - If true, will send authentication details. The default is false.

@include "commands/context-create_more.mdx"
4 changes: 2 additions & 2 deletions website/content/commands/context-delete.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Deletes a context. This will succeed if the context is already deleted.

#### Global Options

- `-plain` - Plain output: no colors, no animation.
- `-plain` - Plain output: no colors, no animation. The default is false.
- `-app=<string>` (`-a`) - App to target. Certain commands require a single app target for Waypoint configurations with multiple apps. If you have a single app, then this can be ignored.
- `-project=<string>` (`-p`) - Project to target.
- `-workspace=<string>` (`-w`) - Workspace to operate in.

#### Command Options

- `-all` - Delete all contexts. If this is specified, NAME should not be specified in the command arguments.
- `-all` - Delete all contexts. If this is specified, NAME should not be specified in the command arguments. The default is false.

@include "commands/context-delete_more.mdx"
Loading

0 comments on commit bfe7c7b

Please sign in to comment.