all repos

clerk @ a2ef079f64a5ad301b0e6f4425931ebbb2657a79

missing tooling for ledger/hledger

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

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