jt-consoleutils
Scaffolding and helpers for CLI tools — output abstractions, shell execution, terminal utilities, colorization, and optional build-time metadata support.
Overview
jt-consoleutils provides a small set of focused building blocks for writing
Rust CLI tools:
| Module | What it provides |
|---|---|
output |
Output trait + ConsoleOutput, StringOutput, OutputMode |
shell |
Shell trait + ProcessShell, DryRunShell, MockShell, create() |
colorize |
Rainbow ANSI colorization helper |
colors |
Common ANSI color/reset escape constants |
terminal |
Terminal width detection |
str_utils |
String wrapping and padding helpers |
fs_utils |
Filesystem helpers (recursive copy, etc.) |
help |
Formatted help-text rendering |
version |
version_string(build_date, git_hash) formatter |
build_support |
(feature-gated) emit_build_info() for build.rs |
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
Output
Output is a trait that abstracts where CLI output goes. ConsoleOutput writes
to stdout/stderr; StringOutput captures output in memory (useful in tests).
Both respect OutputMode, which carries verbose, quiet, and dry_run flags.
use ;
Use StringOutput in tests to assert on exactly what was written:
use ;
let mut out = new;
out.writeln;
out.writeln;
assert_eq!;
OutputMode
use OutputMode;
// Verbose mode: extra diagnostic lines are printed.
let verbose = OutputMode ;
// Quiet mode: only errors are shown.
let quiet = OutputMode ;
// Dry-run mode: commands are announced but not executed.
let dry_run = OutputMode ;
Shell
Shell is a trait that abstracts process execution. ProcessShell runs real
commands; DryRunShell announces what it would run without executing anything;
MockShell records calls and returns configurable results — ideal for unit tests.
Use create(dry_run) for the common case:
use ;
Construct a ProcessShell directly if you need custom config:
use ;
use ;
let shell = ProcessShell ;
let mode = default;
let mut out = new;
let exists = shell.command_exists;
let tag = shell.command_output;
Use MockShell in tests:
use ;
use ;
let mut shell = new;
let mode = default;
let mut out = new;
let result = shell
.run_command
.unwrap;
assert!;
assert_eq!;
Feature Flags
| Feature | Default | Description |
|---|---|---|
build-support |
off | Enables build_support::emit_build_info() for use in build.rs |
build-support
Inject a build date and git commit hash into your binary at compile time:
# In your project's Cargo.toml
[]
= { = "0.1", = ["build-support"] }
// In your project's build.rs
// In your application code
const BUILD_DATE: &str = env!;
const GIT_HASH: &str = env!;
BUILD_DATE is computed from the system clock (no external crates) and
GIT_HASH is the short commit hash from git rev-parse --short HEAD, or
"unknown" if git is unavailable.
MSRV
The minimum supported Rust version is 1.85 (Rust 2024 edition).
License
Licensed under either of:
at your option.