[DEPRECATED] Go implementation of plcbundle
1package main
2
3import (
4 "fmt"
5 "os"
6
7 "github.com/spf13/cobra"
8 "tangled.org/atscan.net/plcbundle/cmd/plcbundle/commands"
9)
10
11func main() {
12 //debug.SetGCPercent(400)
13
14 rootCmd := newRootCommand()
15
16 if err := rootCmd.Execute(); err != nil {
17 os.Exit(1)
18 }
19}
20
21func newRootCommand() *cobra.Command {
22 cmd := &cobra.Command{
23 Use: "plcbundle",
24 Short: "DID PLC Bundle Management Tool",
25 Long: `plcbundle - DID PLC Bundle Management Tool
26
27Tool for archiving AT Protocol's DID PLC Directory operations
28into immutable, cryptographically-chained bundles of 10,000
29operations each.
30
31Documentation: https://tangled.org/@atscan.net/plcbundle`,
32
33 Version: GetVersion(),
34
35 Run: func(cmd *cobra.Command, args []string) {
36 printRootHelp()
37 },
38 }
39
40 // GLOBAL FLAGS (available to all commands)
41 cmd.PersistentFlags().StringP("dir", "C", "", "Repository directory (default: current directory)")
42 cmd.PersistentFlags().BoolP("verbose", "v", false, "Show detailed output and progress")
43 cmd.PersistentFlags().BoolP("quiet", "q", false, "Suppress non-error output")
44 cmd.PersistentFlags().String("handle-resolver", "",
45 "Handle resolver URL (e.g., https://quickdid.smokesignal.tools)")
46
47 // Bundle operations (root level - most common)
48 cmd.AddCommand(commands.NewSyncCommand())
49 cmd.AddCommand(commands.NewCloneCommand())
50 cmd.AddCommand(commands.NewExportCommand())
51 cmd.AddCommand(commands.NewRollbackCommand())
52
53 // Status & info (root level)
54 cmd.AddCommand(commands.NewStatusCommand())
55 cmd.AddCommand(commands.NewLogCommand())
56 cmd.AddCommand(commands.NewLsCommand())
57 cmd.AddCommand(commands.NewOpCommand())
58 //cmd.AddCommand(commands.NewGapsCommand())
59 cmd.AddCommand(commands.NewVerifyCommand())
60 cmd.AddCommand(commands.NewDiffCommand())
61 //cmd.AddCommand(commands.NewStatsCommand())
62 cmd.AddCommand(commands.NewInspectCommand())
63 cmd.AddCommand(commands.NewQueryCommand())
64
65 // Namespaced commands
66 cmd.AddCommand(commands.NewDIDCommand())
67 cmd.AddCommand(commands.NewIndexCommand())
68 cmd.AddCommand(commands.NewMempoolCommand())
69 cmd.AddCommand(commands.NewDetectorCommand())
70
71 // Monitoring & maintenance
72 /*cmd.AddCommand(commands.NewWatchCommand())
73 cmd.AddCommand(commands.NewHealCommand())*/
74 cmd.AddCommand(commands.NewCleanCommand())
75 cmd.AddCommand(commands.NewMigrateCommand())
76
77 // Server
78 cmd.AddCommand(commands.NewServerCommand())
79
80 // Utilities
81 cmd.AddCommand(newVersionCommand())
82 cmd.AddCommand(newCompletionCommand())
83
84 return cmd
85}
86
87func newVersionCommand() *cobra.Command {
88 return &cobra.Command{
89 Use: "version",
90 Short: "Show version information",
91 Run: func(cmd *cobra.Command, args []string) {
92 cmd.Printf("plcbundle version %s\n", GetVersion())
93 cmd.Printf(" commit: %s\n", getGitCommit())
94 cmd.Printf(" built: %s\n", getBuildDate())
95 },
96 }
97}
98
99func newCompletionCommand() *cobra.Command {
100 return &cobra.Command{
101 Use: "completion [bash|zsh|fish|powershell]",
102 Short: "Generate shell completion script",
103 Long: `Generate shell completion script for your shell.
104
105To load completions:
106
107Bash:
108 $ source <(plcbundle completion bash)
109
110 # To load automatically:
111 $ plcbundle completion bash > /etc/bash_completion.d/plcbundle
112
113Zsh:
114 $ plcbundle completion zsh > ~/.zsh/completion/_plcbundle
115
116 # Add to ~/.zshrc:
117 fpath=(~/.zsh/completion $fpath)
118
119Fish:
120 $ plcbundle completion fish > ~/.config/fish/completions/plcbundle.fish`,
121
122 Args: cobra.ExactArgs(1),
123 ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
124 DisableFlagsInUseLine: true,
125
126 RunE: func(cmd *cobra.Command, args []string) error {
127 switch args[0] {
128 case "bash":
129 return cmd.Root().GenBashCompletion(os.Stdout)
130 case "zsh":
131 return cmd.Root().GenZshCompletion(os.Stdout)
132 case "fish":
133 return cmd.Root().GenFishCompletion(os.Stdout, true)
134 case "powershell":
135 return cmd.Root().GenPowerShellCompletion(os.Stdout)
136 }
137 return nil
138 },
139 }
140}
141
142func printRootHelp() {
143 fmt.Print(`plcbundle ` + GetVersion() + ` - DID PLC Bundle Management
144
145Usage: plcbundle <command> [options]
146
147Main Commands:
148 sync Fetch new bundles from PLC
149 clone <url> Clone from remote repository
150 status Show repository status
151 did resolve <did> Resolve DID document
152 server Start HTTP server
153
154Command Groups:
155 Bundle: clone, sync, export, get, rollback
156 Status: status, log, gaps, verify, diff, stats, inspect
157 Ops: op <get|show|find>
158 DID: did <resolve|lookup|history|batch|stats>
159 Index: index <build|repair|stats|verify>
160 Tools: watch, heal, clean, mempool, detector
161
162Getting Started:
163 plcbundle clone https://plc.example.com
164 plcbundle sync
165 plcbundle status
166
167Run 'plcbundle help' for full documentation
168Run 'plcbundle <command> --help' for command help
169`)
170}