feat: add --help support to all commands

Add --help/-h flag handling to 7 commands that were missing it:
sync, status, collect, pull, push, doctor, ui.

Previously, running e.g. 'skillshare push --help' would execute
the push instead of showing help. Now all commands safely show
usage info when --help is passed.

Also adds wantsHelp() helper to reduce duplication across commands.

Closes #113
This commit is contained in:
Willie
2026-04-01 14:20:51 +08:00
parent 80e6941852
commit 3f7cfc7fbc
8 changed files with 176 additions and 0 deletions
+28
View File
@@ -55,6 +55,11 @@ func displayLocalSkills(skills []sync.LocalSkillInfo) {
}
func cmdCollect(args []string) error {
if wantsHelp(args) {
printCollectHelp()
return nil
}
start := time.Now()
mode, rest, err := parseModeArgs(args)
@@ -290,3 +295,26 @@ func showCollectNextSteps(source string) {
ui.Info("Commit changes: cd %s && git add . && git commit", source)
}
}
func printCollectHelp() {
fmt.Println(`Usage: skillshare collect [target] [options]
Collect local skills from target(s) to source directory.
Arguments:
[target] Target name to collect from (optional)
Options:
--all, -a Collect from all targets
--dry-run, -n Preview changes without applying
--force, -f Skip confirmation prompts
--json Output results as JSON
--project, -p Use project-level config
--global, -g Use global config
--help, -h Show this help
Examples:
skillshare collect claude Collect from Claude target
skillshare collect --all Collect from all targets
skillshare collect --dry-run Preview what would be collected`)
}
+22
View File
@@ -48,6 +48,11 @@ func (r *doctorResult) addInfo(name, message string) {
}
func cmdDoctor(args []string) error {
if wantsHelp(args) {
printDoctorHelp()
return nil
}
mode, rest, err := parseModeArgs(args)
if err != nil {
return err
@@ -1119,3 +1124,20 @@ func printUpdateAvailable(result *versioncheck.CheckResult) {
ui.Info("Update available: %s -> %s", result.CurrentVersion, result.LatestVersion)
ui.Info(" Run: %s", result.InstallMethod.UpgradeCommand())
}
func printDoctorHelp() {
fmt.Println(`Usage: skillshare doctor [options]
Check environment and diagnose issues.
Options:
--json Output results as JSON
--project, -p Use project-level config
--global, -g Use global config
--help, -h Show this help
Examples:
skillshare doctor Run diagnostics
skillshare doctor --json Output as JSON
skillshare doctor -p Check project config`)
}
+5
View File
@@ -92,6 +92,11 @@ func hasFlag(args []string, flag string) bool {
return slices.Contains(args, flag)
}
// wantsHelp returns true if args contain --help or -h.
func wantsHelp(args []string) bool {
return hasFlag(args, "--help") || hasFlag(args, "-h")
}
// ensureEmptySlices recursively walks exported struct fields and replaces nil
// slices with empty slices so json.Marshal produces [] instead of null.
// It handles nested structs and slices of structs.
+21
View File
@@ -22,6 +22,11 @@ const (
)
func cmdPull(args []string) error {
if wantsHelp(args) {
printPullHelp()
return nil
}
start := time.Now()
dryRun := false
force := false
@@ -248,3 +253,19 @@ func resetToRemote(sourcePath, remoteBranch string, spinner *ui.Spinner) error {
}
return nil
}
func printPullHelp() {
fmt.Println(`Usage: skillshare pull [options]
Pull from git remote and sync to all targets.
Options:
--dry-run, -n Preview changes without applying
--force, -f Force-pull (reset local to remote on first pull)
--help, -h Show this help
Examples:
skillshare pull Pull and sync
skillshare pull --dry-run Preview what would happen
skillshare pull --force Discard local, use remote`)
}
+21
View File
@@ -210,6 +210,11 @@ func detectRemoteDefaultBranchForPush(sourcePath string, authEnv []string) strin
}
func cmdPush(args []string) error {
if wantsHelp(args) {
printPushHelp()
return nil
}
start := time.Now()
opts := parsePushArgs(args)
@@ -270,3 +275,19 @@ func cmdPush(args []string) error {
return nil
}
func printPushHelp() {
fmt.Println(`Usage: skillshare push [options]
Commit and push source skills to git remote.
Options:
-m, --message <msg> Commit message (default: "Update skills")
--dry-run, -n Preview changes without applying
--help, -h Show this help
Examples:
skillshare push Push with default message
skillshare push -m "Add new skill" Push with custom message
skillshare push --dry-run Preview what would happen`)
}
+22
View File
@@ -67,6 +67,11 @@ type statusJSONAudit struct {
}
func cmdStatus(args []string) error {
if wantsHelp(args) {
printStatusHelp()
return nil
}
mode, rest, err := parseModeArgs(args)
if err != nil {
return err
@@ -535,6 +540,23 @@ func fetchRemoteSkillVersion() string {
return ""
}
func printStatusHelp() {
fmt.Println(`Usage: skillshare status [options]
Show status of source, skills, and all targets.
Options:
--json Output results as JSON
--project, -p Use project-level config
--global, -g Use global config
--help, -h Show this help
Examples:
skillshare status Show current state
skillshare status --json Output as JSON
skillshare status -p Show project status`)
}
func readSkillVersion(skillFile string) string {
file, err := os.Open(skillFile)
if err != nil {
+29
View File
@@ -56,6 +56,11 @@ type syncModeStats struct {
}
func cmdSync(args []string) error {
if wantsHelp(args) {
printSyncHelp()
return nil
}
// Subcommand: sync extras
if len(args) > 0 && args[0] == "extras" {
return cmdSyncExtras(args[1:])
@@ -755,3 +760,27 @@ func syncSymlinkMode(name string, target config.TargetConfig, source string, dry
return nil
}
func printSyncHelp() {
fmt.Println(`Usage: skillshare sync [options]
Sync skills from source to all configured targets.
Options:
--all Sync skills and extras
--dry-run, -n Preview changes without applying
--force, -f Force sync (overwrite local changes)
--json Output results as JSON
--project, -p Use project-level config
--global, -g Use global config
--help, -h Show this help
Subcommands:
extras Sync only extras (see: skillshare sync extras --help)
Examples:
skillshare sync Sync skills to all targets
skillshare sync --dry-run Preview sync changes
skillshare sync --all Sync skills and extras
skillshare sync -p Sync project-level skills`)
}
+28
View File
@@ -15,6 +15,11 @@ import (
)
func cmdUI(args []string) error {
if wantsHelp(args) {
printUIHelp()
return nil
}
mode, rest, err := parseModeArgs(args)
if err != nil {
return err
@@ -221,3 +226,26 @@ func openBrowser(url string) {
}
_ = cmd.Start()
}
func printUIHelp() {
fmt.Println(`Usage: skillshare ui [options]
Launch the web dashboard.
Options:
--port <port> Server port (default: 19420)
--host <host> Server host (default: 127.0.0.1)
--base-path, -b Base path prefix for reverse proxy
--no-open Don't open browser automatically
--clear-cache Clear cached UI assets and exit
--project, -p Use project-level config
--global, -g Use global config
--help, -h Show this help
Examples:
skillshare ui Launch dashboard
skillshare ui --port 8080 Launch on custom port
skillshare ui --no-open Launch without opening browser
skillshare ui -p Launch in project mode
skillshare ui --clear-cache Clear cached UI files`)
}