-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
99 lines (84 loc) · 2.31 KB
/
main.go
File metadata and controls
99 lines (84 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"os"
"github.com/synseqack/aict/internal/tool"
_ "github.com/synseqack/aict/tools/basename"
_ "github.com/synseqack/aict/tools/cat"
_ "github.com/synseqack/aict/tools/checksums"
_ "github.com/synseqack/aict/tools/cut"
_ "github.com/synseqack/aict/tools/df"
_ "github.com/synseqack/aict/tools/diff"
_ "github.com/synseqack/aict/tools/dirname"
_ "github.com/synseqack/aict/tools/doctor"
_ "github.com/synseqack/aict/tools/du"
_ "github.com/synseqack/aict/tools/env"
_ "github.com/synseqack/aict/tools/file"
_ "github.com/synseqack/aict/tools/find"
_ "github.com/synseqack/aict/tools/git"
_ "github.com/synseqack/aict/tools/grep"
_ "github.com/synseqack/aict/tools/head"
_ "github.com/synseqack/aict/tools/ls"
_ "github.com/synseqack/aict/tools/ps"
_ "github.com/synseqack/aict/tools/pwd"
_ "github.com/synseqack/aict/tools/realpath"
_ "github.com/synseqack/aict/tools/sort"
_ "github.com/synseqack/aict/tools/stat"
_ "github.com/synseqack/aict/tools/system"
_ "github.com/synseqack/aict/tools/tail"
_ "github.com/synseqack/aict/tools/tr"
_ "github.com/synseqack/aict/tools/uniq"
_ "github.com/synseqack/aict/tools/wc"
)
func main() {
if err := run(os.Args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "aict: %v\n", err)
os.Exit(1)
}
}
func run(args []string) error {
if len(args) == 0 {
printUsage()
return nil
}
toolName := args[0]
subArgs := args[1:]
if toolName == "help" || toolName == "--help" || toolName == "-h" {
printUsage()
return nil
}
tools := tool.All()
fn, ok := tools[toolName]
if !ok {
fmt.Fprintf(os.Stderr, "aict: unknown command: %s\n", toolName)
fmt.Fprintf(os.Stderr, "Run 'aict help' for usage.\n")
return fmt.Errorf("unknown command: %s", toolName)
}
return fn(subArgs)
}
func printUsage() {
meta := tool.AllMeta()
tools := tool.All()
fmt.Print(`aict - Your command line, built for AI
Usage: aict <command> [flags] [arguments]
Commands:
`)
for name := range tools {
if m, ok := meta[name]; ok {
fmt.Printf(" %-12s %s\n", name, m.Description)
} else {
fmt.Printf(" %s\n", name)
}
}
fmt.Print(`
Output modes:
--xml XML output (default if AICT_XML=1)
--json JSON output
--plain Plain text output
Examples:
aict ls src/
aict grep "func" . -r
aict cat main.go
aict find . -name "*.go"
`)
}