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

Consolidate all App code into Command #1746

Merged
merged 26 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a1149b5
Consolidate all `App` code into `Command`
meatballhat Jun 2, 2023
f3e0f77
Fixing some of the tests
meatballhat Jun 3, 2023
58923b2
Fixing more tests around combining `App` and `Command`
meatballhat Jun 3, 2023
0e4bfae
Merge remote-tracking branch 'origin/main' into app-command-collapse-…
meatballhat Jun 4, 2023
f0abc82
Fixing more tests and panics
meatballhat Jun 4, 2023
35a2755
Remove `App` type
meatballhat Jun 4, 2023
adf81a2
Fixing some tests, giving up (for now) on others
meatballhat Jun 6, 2023
9005335
Fix a few more tests and break many others
meatballhat Jun 7, 2023
5a9784a
Fix (break) a few examples
meatballhat Jun 7, 2023
eea2adc
Mostly fixing things this time
meatballhat Jun 8, 2023
f2fe61c
Fix or skip remaining tests
meatballhat Jun 9, 2023
8e5598f
Merge remote-tracking branch 'origin/main' into app-command-collapse-…
meatballhat Jun 9, 2023
c72fa02
Fix flag action test after merge
meatballhat Jun 9, 2023
76f538b
Fix some golangci-lint bits
meatballhat Jun 9, 2023
e0b109c
Cleanups around `App` :arrow_right: `Command` collapse
meatballhat Jun 9, 2023
2eac7ce
Function receiver naming consistency, adding `Command.Root()`
meatballhat Jun 9, 2023
e58ad0b
Re-introduce optional `command` in help templates
meatballhat Jun 9, 2023
0171f96
Promote docs changes
meatballhat Jun 9, 2023
412c9a7
Start moving examples into separate file
meatballhat Jun 9, 2023
c6eb55c
Move remaining Example funcs to `examples_test.go`
meatballhat Jun 9, 2023
ccbd7d8
Move remaining previously-`App` tests to `command_test.go`
meatballhat Jun 9, 2023
a0eae69
Remove `CommandsByName` type
meatballhat Jun 9, 2023
008c169
Add and use test helper for building `context.Context`
meatballhat Jun 9, 2023
841adc7
Changes per feedback on #1746
meatballhat Jun 12, 2023
6909910
Merge remote-tracking branch 'origin/main' into app-command-collapse-…
meatballhat Jun 12, 2023
c613e65
Approve v3 API change
meatballhat Jun 12, 2023
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
460 changes: 0 additions & 460 deletions app.go

This file was deleted.

3,393 changes: 0 additions & 3,393 deletions app_test.go

This file was deleted.

45 changes: 42 additions & 3 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// cli application can be written as follows:
//
// func main() {
// (&cli.App{}).Run(os.Args)
// (&cli.Command{}).Run(context.Background(), os.Args)
// }
//
// Of course this application does not do much, so let's make this an actual application:
//
// func main() {
// app := &cli.App{
// cmd := &cli.Command{
// Name: "greet",
// Usage: "say a greeting",
// Action: func(c *cli.Context) error {
Expand All @@ -18,6 +18,45 @@
// },
// }
//
// app.Run(os.Args)
// cmd.Run(context.Background(), os.Args)
// }
package cli

import (
"fmt"
"os"
"runtime"
"strings"
)

var (
isTracingOn = os.Getenv("URFAVE_CLI_TRACING") == "on"
)

func tracef(format string, a ...any) {
if !isTracingOn {
return
}

if !strings.HasSuffix(format, "\n") {
format = format + "\n"
}

pc, file, line, _ := runtime.Caller(1)
cf := runtime.FuncForPC(pc)

fmt.Fprintf(
os.Stderr,
strings.Join([]string{
"## URFAVE CLI TRACE ",
file,
":",
fmt.Sprintf("%v", line),
" ",
fmt.Sprintf("(%s)", cf.Name()),
" ",
format,
}, ""),
a...,
)
}
28 changes: 28 additions & 0 deletions cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cli

import (
"bytes"
"context"
"os"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func expectFileContent(t *testing.T, file, got string) {
data, err := os.ReadFile(file)
// Ignore windows line endings
data = bytes.ReplaceAll(data, []byte("\r\n"), []byte("\n"))

r := require.New(t)
r.NoError(err)
r.Equal(got, string(data))
}

func buildTestContext(t *testing.T) context.Context {
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
t.Cleanup(cancel)

return ctx
}
Binary file removed cmd/urfave-cli-genflags/urfave-cli-genflags
Binary file not shown.
Loading