- config: resolve binary dir, load/save .hf-config.json - mode: detect padded-cell vs manual mode via pass_mgr - client: HTTP client wrapper with auth header support - passmgr: pass_mgr integration (get-secret, set, generate) - output: human-readable + JSON output formatting with tables - help: help and help-brief renderer for groups/commands - commands: version, health, config (--url, --acc-mgr-token, show) - auth: token resolution helper (padded-cell auto / manual explicit) - main: command dispatcher with --json global flag support - README: updated with current package layout and status
110 lines
3.3 KiB
Go
110 lines
3.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/commands"
|
|
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/help"
|
|
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/mode"
|
|
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/output"
|
|
)
|
|
|
|
func main() {
|
|
args := os.Args[1:]
|
|
|
|
// Parse global flags first
|
|
args = parseGlobalFlags(args)
|
|
|
|
if len(args) == 0 {
|
|
fmt.Print(help.RenderTopHelp(commands.Version, topGroups()))
|
|
return
|
|
}
|
|
|
|
switch args[0] {
|
|
case "--help", "-h":
|
|
fmt.Print(help.RenderTopHelp(commands.Version, topGroups()))
|
|
case "--help-brief":
|
|
fmt.Print(help.RenderTopHelpBrief(commands.Version, topGroups()))
|
|
case "version":
|
|
commands.RunVersion()
|
|
case "health":
|
|
commands.RunHealth()
|
|
case "config":
|
|
runConfig(args[1:])
|
|
default:
|
|
fmt.Fprintf(os.Stderr, "unknown command: %s\n", args[0])
|
|
fmt.Fprintf(os.Stderr, "Run 'hf --help' for usage.\n")
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
// parseGlobalFlags extracts --json from anywhere in the args and returns remaining args.
|
|
func parseGlobalFlags(args []string) []string {
|
|
var remaining []string
|
|
for _, a := range args {
|
|
switch a {
|
|
case "--json":
|
|
output.JSONMode = true
|
|
default:
|
|
remaining = append(remaining, a)
|
|
}
|
|
}
|
|
return remaining
|
|
}
|
|
|
|
func runConfig(args []string) {
|
|
if len(args) == 0 {
|
|
commands.RunConfigShow()
|
|
return
|
|
}
|
|
for i := 0; i < len(args); i++ {
|
|
switch args[i] {
|
|
case "--url":
|
|
if i+1 >= len(args) {
|
|
output.Error("usage: hf config --url <hf-url>")
|
|
}
|
|
commands.RunConfigURL(args[i+1])
|
|
return
|
|
case "--acc-mgr-token":
|
|
if i+1 >= len(args) {
|
|
output.Error("usage: hf config --acc-mgr-token <token>")
|
|
}
|
|
commands.RunConfigAccMgrToken(args[i+1])
|
|
return
|
|
case "--help", "-h":
|
|
fmt.Println("hf config - View and manage CLI configuration")
|
|
fmt.Println()
|
|
fmt.Println("Usage:")
|
|
fmt.Println(" hf config Show current config")
|
|
fmt.Println(" hf config --url <hf-url> Set HarborForge API URL")
|
|
if !mode.IsPaddedCell() {
|
|
fmt.Println(" hf config --acc-mgr-token <token> Set account-manager token")
|
|
}
|
|
return
|
|
default:
|
|
output.Errorf("unknown config flag: %s", args[i])
|
|
}
|
|
}
|
|
}
|
|
|
|
// topGroups returns the full command tree for help rendering.
|
|
// TODO: permission awareness will be added when auth introspection is available.
|
|
func topGroups() []help.Group {
|
|
return []help.Group{
|
|
{Name: "version", Description: "Show CLI version", Permitted: true},
|
|
{Name: "health", Description: "Check API health", Permitted: true},
|
|
{Name: "config", Description: "View and manage CLI configuration", Permitted: true},
|
|
{Name: "user", Description: "Manage users", Permitted: true},
|
|
{Name: "role", Description: "Manage roles and permissions", Permitted: true},
|
|
{Name: "permission", Description: "List permissions", Permitted: true},
|
|
{Name: "project", Description: "Manage projects", Permitted: true},
|
|
{Name: "milestone", Description: "Manage milestones", Permitted: true},
|
|
{Name: "task", Description: "Manage tasks", Permitted: true},
|
|
{Name: "meeting", Description: "Manage meetings", Permitted: true},
|
|
{Name: "support", Description: "Manage support tickets", Permitted: true},
|
|
{Name: "propose", Description: "Manage proposals", Permitted: true},
|
|
{Name: "monitor", Description: "Monitor servers and API keys", Permitted: true},
|
|
}
|
|
}
|