Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ Notable changes to Chrono Mock, newest first. The format follows

### Fixed

- **`--dry-run` approved sessions the real run refuses.** An impossible `--at` (month 13, 30 February,
25:61) was printed as the plan and exited 0, while the real run was refused by the core with
exit 1. A file Windows will not start (a text file, an empty `.exe`, one cut short inside its
header, a library) was planned as "native injection" and exited 0, while the real run failed to
launch it with exit 2. The plan now refuses both with the code the real run gives, the moment in
the core's own words. It reads the header where the file says it is, so a program whose header
sits far into the file is still planned. What it leaves to the real run is whether the rest of the
file is intact. A batch script is still planned, because Windows starts it through the command
interpreter. `chronomock.plan/1` names that target state `not_a_program`.
- **A preset that dates from the application's file carried the time of day the file was written.**
`chrono run --preset date-before-install` without `--param` set the session to 23:00:35 the day
before installation, where the same preset given the date by hand sets midnight. A date parameter
is a date, so the file's creation date now arrives as midnight too. The trial presets were not
affected, because they set their own time.
- **Asking for help was answered as a mistake.** `chrono help` said "unknown command", and
`chrono calc --help` said "unknown flag" and exited 1, while `chrono --help` exited 0. `help`,
`run --help` and `calc --help` (and `-h`) now print the usage and exit 0. `--help` further along the
command line is still passed to the application. `--at` followed by another flag, or by `-h`, now
says that `--at` is missing its moment, instead of a sentence about a "shift".
- **Ending a session sent the application's timers back, and left its web pages on the session
date.** A session often ends while the application keeps running: `--ticks` ran out, or the
session was stopped from the window. The application was then handed back the real value of every
Expand Down
22 changes: 22 additions & 0 deletions crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,28 @@ pub(crate) fn print_usage() {
eprintln!("usage: chrono license [--components] (also --license) the licence, the warranty disclaimer, and every bundled component with its version");
}

/// Whether a word is the help flag, which every command answers.
pub(crate) fn is_help_flag(word: &str) -> bool {
matches!(word, "--help" | "-h")
}

/// Whether the words after a command ask for its help: `run --help`, `calc -h`. Only the FIRST word
/// counts, because `--help` further along can be meant for the target (`--args --help`).
pub(crate) fn asks_for_help(rest: &[String]) -> bool {
rest.first().is_some_and(|word| is_help_flag(word))
}

/// The usage a command was asked for, and exit 0 - it is an answer, not a refusal. `calc --help`
/// used to say "unknown flag" and exit 1 while `chrono --help` beside it exited 0.
pub(crate) fn print_help_for(command: &str) -> i32 {
if command == "calc" {
print_calc_usage();
} else {
print_usage();
}
0
}

pub(crate) fn print_calc_usage() {
eprintln!("usage: chrono calc [--base <today|now|YYYY-MM-DDTHH:MM:SS>] [--base-utc <YYYY-MM-DDTHH:MM:SS[Z]>] [--shift <±N<unit>>]... [--set-time <HH:MM:SS>] [--snap <target>] [--nearest <target>] [--to-zone <+HH:MM>] [--zone <+HH:MM>] [--calendar <us-banking|us-federal|pl>] [--format <mask>] [--json]");
eprintln!(" or: chrono calc --preset <id> [--param id=value]... (named moment, e.g. month-end, trial-first-day-after)");
Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ mod zone;

use calc::calc_run;
use cdp_probe::{cdp_date_probe, cdp_launch_probe, cdp_probe, cdp_shim_probe};
use cli::{print_license, print_usage, print_version};
use cli::{asks_for_help, print_help_for, print_license, print_usage, print_version};
use core::core_mode;
use run::driver_run;

fn main() {
let args: Vec<String> = std::env::args().collect();
let code = match args.get(1).map(String::as_str) {
Some("__core") => core_mode(),
Some(command @ ("run" | "calc")) if asks_for_help(&args[2..]) => print_help_for(command),
Some("run") => driver_run(&args[2..]),
Some("calc") => calc_run(&args[2..]),
Some("__cdp-probe") => cdp_probe(&args[2..]),
Expand All @@ -83,7 +84,7 @@ fn main() {
0
}
Some("license") | Some("--license") => print_license(&args[2..]),
Some("--help") | Some("-h") | None => {
Some("--help") | Some("-h") | Some("help") | None => {
print_usage();
0
}
Expand Down
Loading
Loading