clerk/internal/cli/cli.go (view raw)
| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "github.com/urfave/cli/v3" |
| 7 | ) |
| 8 | |
| 9 | type Cli struct { |
| 10 | version string |
| 11 | } |
| 12 | |
| 13 | func New(version string) *Cli { |
| 14 | return &Cli{ |
| 15 | version: version, |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | func (c *Cli) Run(ctx context.Context, args []string) error { |
| 20 | cmd := &cli.Command{ |
| 21 | Name: "clerk", |
| 22 | Usage: "missing pta tooling", |
| 23 | Version: c.version, |
| 24 | EnableShellCompletion: true, |
| 25 | UseShortOptionHandling: true, |
| 26 | Commands: []*cli.Command{ |
| 27 | { |
| 28 | Name: "format", |
| 29 | Usage: "reformat journal files", |
| 30 | Action: c.formatAction, |
| 31 | Arguments: []cli.Argument{&cli.StringArgs{ |
| 32 | Name: "journals", |
| 33 | UsageText: "(path to journal files/directories (stdin if empty))", |
| 34 | Min: 0, |
| 35 | Max: -1, |
| 36 | }}, |
| 37 | Flags: []cli.Flag{ |
| 38 | &cli.BoolFlag{ |
| 39 | Name: "write", |
| 40 | Aliases: []string{"w"}, |
| 41 | Usage: "write result back to file instead of stdout", |
| 42 | }, |
| 43 | &cli.BoolFlag{ |
| 44 | Name: "check", |
| 45 | Aliases: []string{"c"}, |
| 46 | Usage: "exit code 0 if already formatted, 1 otherwise", |
| 47 | }, |
| 48 | &cli.BoolFlag{ |
| 49 | Name: "diff", |
| 50 | Aliases: []string{"d"}, |
| 51 | Usage: "display diffs instead of rewriting files", |
| 52 | }, |
| 53 | &cli.BoolFlag{ |
| 54 | Name: "list", |
| 55 | Aliases: []string{"l"}, |
| 56 | Usage: "list files whose formatting differs", |
| 57 | }, |
| 58 | }, |
| 59 | }, |
| 60 | { |
| 61 | Name: "tags", |
| 62 | Usage: "generate a tags file for journal entries", |
| 63 | Action: c.tagsAction, |
| 64 | Flags: []cli.Flag{&cli.StringFlag{ |
| 65 | Name: "out", |
| 66 | Aliases: []string{"o"}, |
| 67 | Usage: "output file, set to - for stdout", |
| 68 | Value: "tags", |
| 69 | }}, |
| 70 | Arguments: []cli.Argument{&cli.StringArgs{ |
| 71 | Name: "journals", |
| 72 | UsageText: "(path to journal files/directories)", |
| 73 | Min: 0, |
| 74 | Max: -1, |
| 75 | }}, |
| 76 | }, |
| 77 | { |
| 78 | Name: "lsp", |
| 79 | Usage: "lsp server", |
| 80 | Action: c.lspAction, |
| 81 | }, |
| 82 | { |
| 83 | Name: "lint", |
| 84 | Usage: "lint journal files for common mistakes", |
| 85 | Action: c.lintAction, |
| 86 | Flags: []cli.Flag{ |
| 87 | &cli.StringFlag{ |
| 88 | Name: "format", |
| 89 | Aliases: []string{"f"}, |
| 90 | Usage: "output format: text, json", |
| 91 | Value: "text", |
| 92 | }, |
| 93 | &cli.StringFlag{ |
| 94 | Name: "path-style", |
| 95 | Usage: "file path style: basename, relative, absolute", |
| 96 | Value: "relative", |
| 97 | }, |
| 98 | }, |
| 99 | Arguments: []cli.Argument{&cli.StringArgs{ |
| 100 | Name: "journals", |
| 101 | UsageText: "(path to journal files/directories (stdin if empty))", |
| 102 | Min: 0, |
| 103 | Max: -1, |
| 104 | }}, |
| 105 | }, |
| 106 | }, |
| 107 | } |
| 108 | return cmd.Run(ctx, args) |
| 109 | } |