all repos

clerk @ f3b258b

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
lsp: init server, report diagnostics, 19 days 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
		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:   "lsp",
62
				Usage:  "lsp server",
63
				Action: c.lspAction,
64
			},
65
			{
66
				Name:   "tags",
67
				Usage:  "generate a tags file for journal entries",
68
				Action: c.tagsAction,
69
				Flags: []cli.Flag{&cli.StringFlag{
70
					Name:    "out",
71
					Aliases: []string{"o"},
72
					Usage:   "output file, set to - for stdout",
73
					Value:   "tags",
74
				}},
75
				Arguments: []cli.Argument{&cli.StringArgs{
76
					Name:      "journals",
77
					UsageText: "(path to journal files/directories)",
78
					Min:       0,
79
					Max:       -1,
80
				}},
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
}