all repos

clerk @ e00aad86c5586c1f5cc228ee593c69d722775f53

missing tooling for ledger/hledger

clerk/internal/cli/cli.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
cli: update commands descriptions, 1 month ago
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
		Commands: []*cli.Command{
26
			{
27
				Name:   "lsp",
28
				Usage:  "Run LSP server, to be used by editors",
29
				Action: c.lspAction,
30
			},
31
			{
32
				Name:                   "format",
33
				Usage:                  "Format journal files",
34
				Action:                 c.formatAction,
35
				UseShortOptionHandling: true,
36
				Arguments: []cli.Argument{&cli.StringArgs{
37
					Name:      "journals",
38
					UsageText: "(path to journal files/directories (stdin if empty))",
39
					Min:       0,
40
					Max:       -1,
41
				}},
42
				Flags: []cli.Flag{
43
					&cli.BoolFlag{
44
						Name:    "write",
45
						Aliases: []string{"w"},
46
						Usage:   "write result back to file instead of stdout",
47
					},
48
					&cli.BoolFlag{
49
						Name:    "check",
50
						Aliases: []string{"c"},
51
						Usage:   "exit code 0 if already formatted, 1 otherwise",
52
					},
53
					&cli.BoolFlag{
54
						Name:    "diff",
55
						Aliases: []string{"d"},
56
						Usage:   "display diffs instead of rewriting files",
57
					},
58
					&cli.BoolFlag{
59
						Name:    "list",
60
						Aliases: []string{"l"},
61
						Usage:   "list files whose formatting differs",
62
					},
63
				},
64
			},
65
			{
66
				Name:   "lint",
67
				Usage:  "Lint journal files",
68
				Action: c.lintAction,
69
				Flags: []cli.Flag{
70
					&cli.StringFlag{
71
						Name:    "format",
72
						Aliases: []string{"f"},
73
						Usage:   "output format: text, json",
74
						Value:   "text",
75
					},
76
					&cli.StringFlag{
77
						Name:  "path-style",
78
						Usage: "file path style: basename, relative, absolute",
79
						Value: "relative",
80
					},
81
				},
82
				Arguments: []cli.Argument{&cli.StringArgs{
83
					Name:      "journals",
84
					UsageText: "(path to journal files/directories (stdin if empty))",
85
					Min:       0,
86
					Max:       -1,
87
				}},
88
			},
89
		},
90
	}
91
	return cmd.Run(ctx, args)
92
}