cli.v

3.2 KB · raw

1//! Command line entry: dispatch table, usage text and exit codes.2//!3//! Exit codes are fixed across every command: 0 success, 1 refusal or error,4//! 2 bad usage. Each command returns its code; nothing else calls `exit`.56module cli78// Read from VERSION at build time, so the binary and the manifest cannot drift.9pub const version = $embed_file('../../VERSION').to_string().trim_space()1011const usage = 'koh ${version} — one SQLite file per repo, one line of history1213usage: koh <command> [options]1415everyday16  save <message> [--agent <m>] [--session <s>]   snapshot the working tree17  checkpoint <message>                           save, even with no changes18  status                                         what changed since the last save19  log [--since <expr>] [--session <s>]           the line, newest first20  diff [<id>] [<id1> <id2>] [--session last|<s>] unified diff2122going back23  undo [n] [--session]                           step back n saves24  revert                                         discard unsaved changes25  load <id> | --checkpoint                       restore any save2627sync28  remote                                         choose S3 or a folder, once per machine29  offer                                          send new saves to the remote30  steal [<name>] [--list] [--mine|--theirs]      bring in saves from the remote3132occasional33  flag <id> [--reason "..."] | --clear <id>      mark a save unsafe34  pluck <id> [--reverse] [--dry-run] [path...]   apply one save, or its inverse35  peek <id>                                      restore a save into a temp folder3637setup and care38  init                                           create .koh here39  doctor [--backup <path>]                       integrity check and cleanup40  strip <path> [--save <id>]                     remove a path from history4142  man [<command>]                                 the manual, built in43  saves / checkpoints open the history view on that tab44  --json on any command that prints data, --yes to skip a confirm prompt'4546pub fn run(argv []string) int {47	if argv.len < 2 {48		eprintln(usage)49		return 250	}51	rest := argv[2..]52	match argv[1] {53		'--version', '-v' {54			println('koh ${version}')55			return 056		}57		'--help', '-h' {58			println(usage)59			return 060		}61		'help', 'man' {62			return cmd_man(rest)63		}64		'init' {65			return cmd_init(rest)66		}67		'save' {68			return cmd_save(rest, false)69		}70		'checkpoint' {71			return cmd_save(rest, true)72		}73		'status' {74			return cmd_status(rest)75		}76		'log' {77			return cmd_log(rest)78		}79		'saves' {80			return cmd_saves(rest)81		}82		'checkpoints' {83			return cmd_checkpoints(rest)84		}85		'diff' {86			return cmd_diff(rest)87		}88		'undo' {89			return cmd_undo(rest)90		}91		'revert' {92			return cmd_revert(rest)93		}94		'load' {95			return cmd_load(rest)96		}97		'flag' {98			return cmd_flag(rest)99		}100		'pluck' {101			return cmd_pluck(rest)102		}103		'peek' {104			return cmd_peek(rest)105		}106		'doctor' {107			return cmd_doctor(rest)108		}109		'strip' {110			return cmd_strip(rest)111		}112		'remote' {113			return cmd_remote(rest)114		}115		'offer' {116			return cmd_offer(rest)117		}118		'steal' {119			return cmd_steal(rest)120		}121		else {122			eprintln('  koh: unknown command "${argv[1]}"')123			eprintln('  run "koh --help" for the command list')124			return 2125		}126	}127}