Skip to content

Commit

Permalink
Change golines to 120
Browse files Browse the repository at this point in the history
  • Loading branch information
FollowTheProcess committed Jan 16, 2025
1 parent 736080c commit 85ec509
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 16 deletions.
75 changes: 61 additions & 14 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,59 @@ func TestSubCommandExecute(t *testing.T) {
wantErr: false,
},
{
name: "invoke sub1 with arg terminator",
stdout: "Hello from sub1, my args were: [my subcommand args more args here], force was true, something was here, extra args: [more args here]",
stderr: "",
args: []string{"sub1", "my", "subcommand", "args", "--force", "--something", "here", "--", "more", "args", "here"},
name: "invoke sub1 with arg terminator",
stdout: "Hello from sub1, my args were: [my subcommand args more args here], force was true, something was here, extra args: [more args here]",
stderr: "",
args: []string{
"sub1",
"my",
"subcommand",
"args",
"--force",
"--something",
"here",
"--",
"more",
"args",
"here",
},
wantErr: false,
},
{
name: "invoke sub1 with sub1 in the arg list",
stdout: "Hello from sub1, my args were: [my sub1 args sub1 more args here], force was true, something was here, extra args: []",
stderr: "",
args: []string{"sub1", "my", "sub1", "args", "sub1", "--force", "--something", "here", "more", "args", "here"},
name: "invoke sub1 with sub1 in the arg list",
stdout: "Hello from sub1, my args were: [my sub1 args sub1 more args here], force was true, something was here, extra args: []",
stderr: "",
args: []string{
"sub1",
"my",
"sub1",
"args",
"sub1",
"--force",
"--something",
"here",
"more",
"args",
"here",
},
wantErr: false,
},
{
name: "invoke sub1 with sub1 as a flag value",
stdout: "Hello from sub1, my args were: [my subcommand args more args here], force was true, something was sub2, extra args: []",
stderr: "",
args: []string{"sub1", "my", "subcommand", "args", "--force", "--something", "sub2", "more", "args", "here"},
name: "invoke sub1 with sub1 as a flag value",
stdout: "Hello from sub1, my args were: [my subcommand args more args here], force was true, something was sub2, extra args: []",
stderr: "",
args: []string{
"sub1",
"my",
"subcommand",
"args",
"--force",
"--something",
"sub2",
"more",
"args",
"here",
},
wantErr: false,
},
{
Expand Down Expand Up @@ -334,7 +369,13 @@ func TestPositionalArgs(t *testing.T) {
cli.OptionalArg("dest", "The destination path", "dest.txt"), // Dest has a default
cli.RequiredArg("something", "Another arg"), // Required again
cli.Run(func(cmd *cli.Command, args []string) error {
fmt.Fprintf(cmd.Stdout(), "src: %s, dest: %s, something: %s\n", cmd.Arg("src"), cmd.Arg("dest"), cmd.Arg("something"))
fmt.Fprintf(
cmd.Stdout(),
"src: %s, dest: %s, something: %s\n",
cmd.Arg("src"),
cmd.Arg("dest"),
cmd.Arg("something"),
)
return nil
}),
},
Expand All @@ -349,7 +390,13 @@ func TestPositionalArgs(t *testing.T) {
cli.OptionalArg("dest", "The destination path", "default-dest.txt"), // Dest has a default
cli.RequiredArg("something", "Another arg"), // Required again
cli.Run(func(cmd *cli.Command, args []string) error {
fmt.Fprintf(cmd.Stdout(), "src: %s, dest: %s, something: %s\n", cmd.Arg("src"), cmd.Arg("dest"), cmd.Arg("something"))
fmt.Fprintf(
cmd.Stdout(),
"src: %s, dest: %s, something: %s\n",
cmd.Arg("src"),
cmd.Arg("dest"),
cmd.Arg("something"),
)
return nil
}),
},
Expand Down
5 changes: 4 additions & 1 deletion examples/namedargs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ func run() error {
cmd, err := cli.New(
"copy", // A fictional copy command
cli.Short("Copy a file from a src to a destination"),
cli.RequiredArg("src", "The file to copy from"), // src is required, failure to provide it will error
cli.RequiredArg(
"src",
"The file to copy from",
), // src is required, failure to provide it will error
cli.OptionalArg("dest", "The destination to copy to", "./dest"), // dest has a default if not provided
cli.Stdout(os.Stdout),
cli.Example("Copy a file to somewhere", "copy src.txt ./some/where/else"),
Expand Down
7 changes: 6 additions & 1 deletion internal/flag/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ func TestParse(t *testing.T) {
test.False(t, exists)
test.Equal(t, f, nil)

test.EqualFunc(t, set.Args(), []string{"some", "args", "here", "no", "flags", "extra", "args"}, slices.Equal)
test.EqualFunc(
t,
set.Args(),
[]string{"some", "args", "here", "no", "flags", "extra", "args"},
slices.Equal,
)
test.EqualFunc(t, set.ExtraArgs(), []string{"extra", "args"}, slices.Equal)
},
args: []string{"some", "args", "here", "no", "flags", "--", "extra", "args"},
Expand Down

0 comments on commit 85ec509

Please sign in to comment.