cli.v

2.0 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 save2627setup28  init                                           create .koh here2930  --json on any command that prints data, --yes to skip a confirm prompt'3132pub fn run(argv []string) int {33	if argv.len < 2 {34		eprintln(usage)35		return 236	}37	rest := argv[2..]38	match argv[1] {39		'--version', '-v' {40			println('koh ${version}')41			return 042		}43		'--help', '-h', 'help' {44			println(usage)45			return 046		}47		'init' {48			return cmd_init(rest)49		}50		'save' {51			return cmd_save(rest, false)52		}53		'checkpoint' {54			return cmd_save(rest, true)55		}56		'status' {57			return cmd_status(rest)58		}59		'log' {60			return cmd_log(rest)61		}62		'diff' {63			return cmd_diff(rest)64		}65		'undo' {66			return cmd_undo(rest)67		}68		'revert' {69			return cmd_revert(rest)70		}71		'load' {72			return cmd_load(rest)73		}74		else {75			eprintln('  koh: unknown command "${argv[1]}"')76			eprintln('  run "koh --help" for the command list')77			return 278		}79	}80}