Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: simplify and clarify usage text #7277

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 5 additions & 18 deletions cmd/dagger/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,15 @@ var outputPath string
var jsonOutput bool

var callCmd = &FuncCommand{
Name: "call [options]",
Short: "Call a module function",
Long: strings.ReplaceAll(`Call a module function and print the result.

If the last argument is either a Container, Directory, or File, the pipeline
will be evaluated (the result of calling ´sync´) without presenting any output.
Providing the ´--output´ option (shorthand: ´-o´) is equivalent to calling
´export´ instead. To print a property of these core objects, continue chaining
by appending it to the end of the command (for example, ´stdout´, ´entries´, or
´contents´).
`,
Name: "call [options] [FUNCTION [FUNCTION...]]",
Copy link
Contributor

@helderco helderco May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[arguments] and <function> are appended to the usage line dynamically based on the existence of arguments or further functions, respectively. So this will produce the following:

dagger call [options] [FUNCTION [FUNCTION...]] [arguments] <function>

[options] only show on call (doesn't include global flags), so leaving as is creates this usage while you keep adding functions (assuming there's constructor arguments):

dagger call [options] [arguments] <function>
dagger call cli <function>
dagger call cli file [arguments] <function>
dagger call cli file name

Notice also that we conventionalized usage syntax here:

Short: "Call a function, or a pipeline of functions",
Long: strings.ReplaceAll(`Call a function, or a pipeline of functions, and print the result`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The strings.ReplaceAll here is no longer needed. It was a clever hack to allow markdown with ´--output´ for example.

"´",
"`",
),
Example: strings.TrimSpace(`
dagger call test
dagger call build -o ./bin/myapp
dagger call lint stdout
`,
),
Init: func(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVar(&jsonOutput, "json", false, "Present result as JSON")
cmd.PersistentFlags().StringVarP(&outputPath, "output", "o", "", "Path in the host to save the result to")
cmd.PersistentFlags().StringVarP(&outputPath, "output", "o", "", "Save the result to a local file or directory.")
},
OnSelectObjectLeaf: func(c *FuncCommand, name string) error {
switch name {
Expand All @@ -55,6 +41,7 @@ dagger call lint stdout
case Terminal:
c.Select("websocketEndpoint")
default:
// FIXME: don't make this an error, it's confusing to users
Copy link
Contributor

@helderco helderco May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error has been replaced with:

Basically any chain that ends in an object that has itself functions, lists them under "Available Functions".

return fmt.Errorf("return type %q requires a sub-command", name)
helderco marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
Expand Down
Loading