cli.v

3.1 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  saves / checkpoints open the history view on that tab43  --json on any command that prints data, --yes to skip a confirm prompt'4445pub fn run(argv []string) int {46	if argv.len < 2 {47		eprintln(usage)48		return 249	}50	rest := argv[2..]51	match argv[1] {52		'--version', '-v' {53			println('koh ${version}')54			return 055		}56		'--help', '-h', 'help' {57			println(usage)58			return 059		}60		'init' {61			return cmd_init(rest)62		}63		'save' {64			return cmd_save(rest, false)65		}66		'checkpoint' {67			return cmd_save(rest, true)68		}69		'status' {70			return cmd_status(rest)71		}72		'log' {73			return cmd_log(rest)74		}75		'saves' {76			return cmd_saves(rest)77		}78		'checkpoints' {79			return cmd_checkpoints(rest)80		}81		'diff' {82			return cmd_diff(rest)83		}84		'undo' {85			return cmd_undo(rest)86		}87		'revert' {88			return cmd_revert(rest)89		}90		'load' {91			return cmd_load(rest)92		}93		'flag' {94			return cmd_flag(rest)95		}96		'pluck' {97			return cmd_pluck(rest)98		}99		'peek' {100			return cmd_peek(rest)101		}102		'doctor' {103			return cmd_doctor(rest)104		}105		'strip' {106			return cmd_strip(rest)107		}108		'remote' {109			return cmd_remote(rest)110		}111		'offer' {112			return cmd_offer(rest)113		}114		'steal' {115			return cmd_steal(rest)116		}117		else {118			eprintln('  koh: unknown command "${argv[1]}"')119			eprintln('  run "koh --help" for the command list')120			return 2121		}122	}123}