//! Command line entry: dispatch table, usage text and exit codes. //! //! Exit codes are fixed across every command: 0 success, 1 refusal or error, //! 2 bad usage. Each command returns its code; nothing else calls `exit`. module cli // Read from VERSION at build time, so the binary and the manifest cannot drift. pub const version = $embed_file('../../VERSION').to_string().trim_space() const usage = 'koh ${version} — one SQLite file per repo, one line of history usage: koh [options] everyday save [--agent ] [--session ] snapshot the working tree checkpoint save, even with no changes status what changed since the last save log [--since ] [--session ] the line, newest first diff [] [ ] [--session last|] unified diff going back undo [n] [--session] step back n saves revert discard unsaved changes load | --checkpoint restore any save sync remote choose S3 or a folder, once per machine offer send new saves to the remote steal [] [--list] [--mine|--theirs] bring in saves from the remote occasional flag [--reason "..."] | --clear mark a save unsafe pluck [--reverse] [--dry-run] [path...] apply one save, or its inverse peek restore a save into a temp folder setup and care init create .koh here doctor [--backup ] integrity check and cleanup strip [--save ] remove a path from history migrate [--lane dev|main] convert a Koh 2 repo here man [] the manual, built in saves / checkpoints open the history view on that tab --json on any command that prints data, --yes to skip a confirm prompt' pub fn run(argv []string) int { if argv.len < 2 { eprintln(usage) return 2 } hand_over(argv) rest := argv[2..] match argv[1] { '--version', '-v' { println('koh ${version}') return 0 } '--help', '-h' { println(usage) return 0 } 'init' { return cmd_init(rest) } 'save' { return cmd_save(rest, false) } 'checkpoint' { return cmd_save(rest, true) } 'status' { return cmd_status(rest) } 'log' { return cmd_log(rest) } 'saves' { return cmd_saves(rest) } 'checkpoints' { return cmd_checkpoints(rest) } 'diff' { return cmd_diff(rest) } 'undo' { return cmd_undo(rest) } 'revert' { return cmd_revert(rest) } 'load' { return cmd_load(rest) } 'flag' { return cmd_flag(rest) } 'pluck' { return cmd_pluck(rest) } 'peek' { return cmd_peek(rest) } 'doctor' { return cmd_doctor(rest) } 'strip' { return cmd_strip(rest) } 'remote' { return cmd_remote(rest) } 'offer' { return cmd_offer(rest) } 'steal' { return cmd_steal(rest) } 'migrate' { return cmd_migrate(rest) } 'man', 'help' { return cmd_man(rest) } else { return usage_error('unknown command "${argv[1]}" — run "koh --help" for the command list') } } }