feat: add SetUsage to support custom help descriptions in CLI (by AI)
This commit is contained in:
parent
e797dc846a
commit
674ec88117
@ -64,6 +64,7 @@ func main() {
|
||||
- **Trace ID Propagation**: Automatically generates a shared Trace ID for all services during startup, ensuring log correlation.
|
||||
- **Secure IPC**: Token-based Unix Domain Socket for `status` and `kill` commands.
|
||||
- **Zero Configuration PID**: Automatic PID management in the system temporary directory.
|
||||
- **Embedded Log Writer**: Automatically registered log writer service with high priority (-100).
|
||||
|
||||
## Commands
|
||||
|
||||
|
||||
16
starter.go
16
starter.go
@ -29,6 +29,7 @@ var (
|
||||
// Default configuration
|
||||
appName = filepath.Base(os.Args[0])
|
||||
appVersion = "1.0.1"
|
||||
appUsage = ""
|
||||
|
||||
// Internal state
|
||||
commands = make(map[string]*command)
|
||||
@ -64,6 +65,9 @@ func init() {
|
||||
AddCommand("restart", "Restart the service", restartCmd)
|
||||
AddCommand("status", "Show service status", statusCmd)
|
||||
AddCommand("kill", "Send signal to a specific service: kill <svc_name> <signal_num>", killCmd)
|
||||
|
||||
// Auto-register log writer service with high priority
|
||||
Register("log-writer", log.WriterService, -100, 0, 0)
|
||||
}
|
||||
|
||||
// Register adds a service to be managed by the starter.
|
||||
@ -83,6 +87,11 @@ func SetAppInfo(name, version string) {
|
||||
appVersion = version
|
||||
}
|
||||
|
||||
// SetUsage sets custom usage text to be displayed in help.
|
||||
func SetUsage(text string) {
|
||||
appUsage = text
|
||||
}
|
||||
|
||||
// AddCommand adds a custom command.
|
||||
func AddCommand(name, desc string, fn func()) {
|
||||
commands[name] = &command{name: name, desc: desc, fn: fn}
|
||||
@ -117,8 +126,11 @@ func Run() {
|
||||
}
|
||||
|
||||
func showHelp() {
|
||||
fmt.Printf("%s (%s)\n\nUsage:\n %s [command] [options]\n\nCommands:\n",
|
||||
appName, appVersion, filepath.Base(os.Args[0]))
|
||||
fmt.Printf("%s (%s)\n\n", appName, appVersion)
|
||||
if appUsage != "" {
|
||||
fmt.Printf("%s\n\n", appUsage)
|
||||
}
|
||||
fmt.Printf("Usage:\n %s [command] [options]\n\nCommands:\n", filepath.Base(os.Args[0]))
|
||||
|
||||
var names []string
|
||||
for cmdName := range commands {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user