//! 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 setup init create .koh here --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 } rest := argv[2..] match argv[1] { '--version', '-v' { println('koh ${version}') return 0 } '--help', '-h', 'help' { 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) } 'diff' { return cmd_diff(rest) } 'undo' { return cmd_undo(rest) } 'revert' { return cmd_revert(rest) } 'load' { return cmd_load(rest) } else { eprintln(' koh: unknown command "${argv[1]}"') eprintln(' run "koh --help" for the command list') return 2 } } }