pub struct App { /* private fields */ }Expand description
The top-level CLI application builder.
Construct with App::new, chain configuration methods, register commands
with App::add_command, then call App::run to parse std::env::args
and dispatch to the appropriate handler.
§Example
use vecli::{App, Command, CommandContext};
fn greet(_ctx: &CommandContext) {
println!("Hello!");
}
let app = App::new("mytool")
.name("My Tool")
.version("1.0.0")
.add_command(Command::new("greet", greet));
// app.run();Implementations§
Source§impl App
impl App
Sourcepub fn new(prog_name: impl Into<String>) -> Self
pub fn new(prog_name: impl Into<String>) -> Self
Creates a new App with the given program name.
prog_name is used in usage strings and error messages (typically the
binary name, e.g. "mytool").
Examples found in repository?
147fn main() {
148 App::new("taskr")
149 .name("Taskr")
150 .description("A toy task manager. Demonstrates all vecli features.")
151 .version("0.1.0")
152 .main(entry)
153 .flag(
154 Flag::global("verbose")
155 .alias("v")
156 .description("Enable verbose output."),
157 )
158 .print_help_on_fail(true)
159 .add_command(
160 Command::new("add", add)
161 .description("Add a new task.")
162 .usage("<task> [--priority <level>]")
163 .flag(
164 Flag::new("priority")
165 .alias("p")
166 .description("Task priority: low, medium, or high."),
167 )
168 .strict_flags(true),
169 )
170 .add_command(
171 Command::new("list", list)
172 .description("List pending tasks.")
173 .flag(
174 Flag::new("all")
175 .alias("a")
176 .description("Include completed tasks."),
177 )
178 .subcommand(
179 Command::new("urgent", list_urgent)
180 .description("List only high-priority tasks."),
181 ),
182 )
183 .add_command(
184 Command::new("done", done)
185 .description("Mark a task as done.")
186 .usage("<task>"),
187 )
188 .add_command(
189 Command::parent("config")
190 .description("Manage taskr configuration.")
191 .print_help_if_no_args(true)
192 .subcommand(
193 Command::new("set", config_set)
194 .description("Set a config value.")
195 .usage("<key> <value>"),
196 )
197 .subcommand(Command::new("show", config_show).description("Show current config.")),
198 )
199 .add_command(Command::new("clear", clear).description("Clear all tasks."))
200 .run();
201}Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Sets the display name shown in help and version output.
Examples found in repository?
147fn main() {
148 App::new("taskr")
149 .name("Taskr")
150 .description("A toy task manager. Demonstrates all vecli features.")
151 .version("0.1.0")
152 .main(entry)
153 .flag(
154 Flag::global("verbose")
155 .alias("v")
156 .description("Enable verbose output."),
157 )
158 .print_help_on_fail(true)
159 .add_command(
160 Command::new("add", add)
161 .description("Add a new task.")
162 .usage("<task> [--priority <level>]")
163 .flag(
164 Flag::new("priority")
165 .alias("p")
166 .description("Task priority: low, medium, or high."),
167 )
168 .strict_flags(true),
169 )
170 .add_command(
171 Command::new("list", list)
172 .description("List pending tasks.")
173 .flag(
174 Flag::new("all")
175 .alias("a")
176 .description("Include completed tasks."),
177 )
178 .subcommand(
179 Command::new("urgent", list_urgent)
180 .description("List only high-priority tasks."),
181 ),
182 )
183 .add_command(
184 Command::new("done", done)
185 .description("Mark a task as done.")
186 .usage("<task>"),
187 )
188 .add_command(
189 Command::parent("config")
190 .description("Manage taskr configuration.")
191 .print_help_if_no_args(true)
192 .subcommand(
193 Command::new("set", config_set)
194 .description("Set a config value.")
195 .usage("<key> <value>"),
196 )
197 .subcommand(Command::new("show", config_show).description("Show current config.")),
198 )
199 .add_command(Command::new("clear", clear).description("Clear all tasks."))
200 .run();
201}Sourcepub fn description(self, desc: impl Into<String>) -> Self
pub fn description(self, desc: impl Into<String>) -> Self
Sets the description shown in the app-level help output.
Examples found in repository?
147fn main() {
148 App::new("taskr")
149 .name("Taskr")
150 .description("A toy task manager. Demonstrates all vecli features.")
151 .version("0.1.0")
152 .main(entry)
153 .flag(
154 Flag::global("verbose")
155 .alias("v")
156 .description("Enable verbose output."),
157 )
158 .print_help_on_fail(true)
159 .add_command(
160 Command::new("add", add)
161 .description("Add a new task.")
162 .usage("<task> [--priority <level>]")
163 .flag(
164 Flag::new("priority")
165 .alias("p")
166 .description("Task priority: low, medium, or high."),
167 )
168 .strict_flags(true),
169 )
170 .add_command(
171 Command::new("list", list)
172 .description("List pending tasks.")
173 .flag(
174 Flag::new("all")
175 .alias("a")
176 .description("Include completed tasks."),
177 )
178 .subcommand(
179 Command::new("urgent", list_urgent)
180 .description("List only high-priority tasks."),
181 ),
182 )
183 .add_command(
184 Command::new("done", done)
185 .description("Mark a task as done.")
186 .usage("<task>"),
187 )
188 .add_command(
189 Command::parent("config")
190 .description("Manage taskr configuration.")
191 .print_help_if_no_args(true)
192 .subcommand(
193 Command::new("set", config_set)
194 .description("Set a config value.")
195 .usage("<key> <value>"),
196 )
197 .subcommand(Command::new("show", config_show).description("Show current config.")),
198 )
199 .add_command(Command::new("clear", clear).description("Clear all tasks."))
200 .run();
201}Sourcepub fn version(self, version: impl Into<String>) -> Self
pub fn version(self, version: impl Into<String>) -> Self
Sets the version string shown by --version.
Examples found in repository?
147fn main() {
148 App::new("taskr")
149 .name("Taskr")
150 .description("A toy task manager. Demonstrates all vecli features.")
151 .version("0.1.0")
152 .main(entry)
153 .flag(
154 Flag::global("verbose")
155 .alias("v")
156 .description("Enable verbose output."),
157 )
158 .print_help_on_fail(true)
159 .add_command(
160 Command::new("add", add)
161 .description("Add a new task.")
162 .usage("<task> [--priority <level>]")
163 .flag(
164 Flag::new("priority")
165 .alias("p")
166 .description("Task priority: low, medium, or high."),
167 )
168 .strict_flags(true),
169 )
170 .add_command(
171 Command::new("list", list)
172 .description("List pending tasks.")
173 .flag(
174 Flag::new("all")
175 .alias("a")
176 .description("Include completed tasks."),
177 )
178 .subcommand(
179 Command::new("urgent", list_urgent)
180 .description("List only high-priority tasks."),
181 ),
182 )
183 .add_command(
184 Command::new("done", done)
185 .description("Mark a task as done.")
186 .usage("<task>"),
187 )
188 .add_command(
189 Command::parent("config")
190 .description("Manage taskr configuration.")
191 .print_help_if_no_args(true)
192 .subcommand(
193 Command::new("set", config_set)
194 .description("Set a config value.")
195 .usage("<key> <value>"),
196 )
197 .subcommand(Command::new("show", config_show).description("Show current config.")),
198 )
199 .add_command(Command::new("clear", clear).description("Clear all tasks."))
200 .run();
201}Sourcepub fn print_help_if_no_args(self, show: bool) -> Self
pub fn print_help_if_no_args(self, show: bool) -> Self
When true, prints help and exits if no arguments are provided.
Mutually exclusive with App::main. If both are set, the main entry
point takes priority and a warning is printed to stderr.
Sourcepub fn print_help_on_fail(self, show: bool) -> Self
pub fn print_help_on_fail(self, show: bool) -> Self
When true, prints the full help listing after any dispatch error.
Examples found in repository?
147fn main() {
148 App::new("taskr")
149 .name("Taskr")
150 .description("A toy task manager. Demonstrates all vecli features.")
151 .version("0.1.0")
152 .main(entry)
153 .flag(
154 Flag::global("verbose")
155 .alias("v")
156 .description("Enable verbose output."),
157 )
158 .print_help_on_fail(true)
159 .add_command(
160 Command::new("add", add)
161 .description("Add a new task.")
162 .usage("<task> [--priority <level>]")
163 .flag(
164 Flag::new("priority")
165 .alias("p")
166 .description("Task priority: low, medium, or high."),
167 )
168 .strict_flags(true),
169 )
170 .add_command(
171 Command::new("list", list)
172 .description("List pending tasks.")
173 .flag(
174 Flag::new("all")
175 .alias("a")
176 .description("Include completed tasks."),
177 )
178 .subcommand(
179 Command::new("urgent", list_urgent)
180 .description("List only high-priority tasks."),
181 ),
182 )
183 .add_command(
184 Command::new("done", done)
185 .description("Mark a task as done.")
186 .usage("<task>"),
187 )
188 .add_command(
189 Command::parent("config")
190 .description("Manage taskr configuration.")
191 .print_help_if_no_args(true)
192 .subcommand(
193 Command::new("set", config_set)
194 .description("Set a config value.")
195 .usage("<key> <value>"),
196 )
197 .subcommand(Command::new("show", config_show).description("Show current config.")),
198 )
199 .add_command(Command::new("clear", clear).description("Clear all tasks."))
200 .run();
201}Sourcepub fn strict_flags(self, strict: bool) -> Self
pub fn strict_flags(self, strict: bool) -> Self
When true, aborts with an error if an unknown app-level flag is passed.
When false (the default), unknown flags produce a warning and execution continues.
Per-command strict mode is configured separately via Command::strict_flags.
Sourcepub fn add_command(self, command: Command) -> Self
pub fn add_command(self, command: Command) -> Self
Registers a command built with the Command builder.
Examples found in repository?
147fn main() {
148 App::new("taskr")
149 .name("Taskr")
150 .description("A toy task manager. Demonstrates all vecli features.")
151 .version("0.1.0")
152 .main(entry)
153 .flag(
154 Flag::global("verbose")
155 .alias("v")
156 .description("Enable verbose output."),
157 )
158 .print_help_on_fail(true)
159 .add_command(
160 Command::new("add", add)
161 .description("Add a new task.")
162 .usage("<task> [--priority <level>]")
163 .flag(
164 Flag::new("priority")
165 .alias("p")
166 .description("Task priority: low, medium, or high."),
167 )
168 .strict_flags(true),
169 )
170 .add_command(
171 Command::new("list", list)
172 .description("List pending tasks.")
173 .flag(
174 Flag::new("all")
175 .alias("a")
176 .description("Include completed tasks."),
177 )
178 .subcommand(
179 Command::new("urgent", list_urgent)
180 .description("List only high-priority tasks."),
181 ),
182 )
183 .add_command(
184 Command::new("done", done)
185 .description("Mark a task as done.")
186 .usage("<task>"),
187 )
188 .add_command(
189 Command::parent("config")
190 .description("Manage taskr configuration.")
191 .print_help_if_no_args(true)
192 .subcommand(
193 Command::new("set", config_set)
194 .description("Set a config value.")
195 .usage("<key> <value>"),
196 )
197 .subcommand(Command::new("show", config_show).description("Show current config.")),
198 )
199 .add_command(Command::new("clear", clear).description("Clear all tasks."))
200 .run();
201}Sourcepub fn flag(self, flag: Flag) -> Self
pub fn flag(self, flag: Flag) -> Self
Registers a flag on the app.
If the flag was created with Flag::global, it is available to all commands
and merged into CommandContext::flags automatically. Otherwise it is treated
as an entry-point flag, visible in the OPTIONS section of help and delivered
via PassedFlags to the main entry handler.
Examples found in repository?
147fn main() {
148 App::new("taskr")
149 .name("Taskr")
150 .description("A toy task manager. Demonstrates all vecli features.")
151 .version("0.1.0")
152 .main(entry)
153 .flag(
154 Flag::global("verbose")
155 .alias("v")
156 .description("Enable verbose output."),
157 )
158 .print_help_on_fail(true)
159 .add_command(
160 Command::new("add", add)
161 .description("Add a new task.")
162 .usage("<task> [--priority <level>]")
163 .flag(
164 Flag::new("priority")
165 .alias("p")
166 .description("Task priority: low, medium, or high."),
167 )
168 .strict_flags(true),
169 )
170 .add_command(
171 Command::new("list", list)
172 .description("List pending tasks.")
173 .flag(
174 Flag::new("all")
175 .alias("a")
176 .description("Include completed tasks."),
177 )
178 .subcommand(
179 Command::new("urgent", list_urgent)
180 .description("List only high-priority tasks."),
181 ),
182 )
183 .add_command(
184 Command::new("done", done)
185 .description("Mark a task as done.")
186 .usage("<task>"),
187 )
188 .add_command(
189 Command::parent("config")
190 .description("Manage taskr configuration.")
191 .print_help_if_no_args(true)
192 .subcommand(
193 Command::new("set", config_set)
194 .description("Set a config value.")
195 .usage("<key> <value>"),
196 )
197 .subcommand(Command::new("show", config_show).description("Show current config.")),
198 )
199 .add_command(Command::new("clear", clear).description("Clear all tasks."))
200 .run();
201}Sourcepub fn add_command_param(
self,
name: impl Into<String>,
flags: Option<Vec<Flag>>,
description: impl Into<String>,
handler: fn(&CommandContext),
usage: Option<impl Into<String>>,
strict_flags: bool,
print_help_if_no_args: bool,
subcommands: Vec<Command>,
) -> Self
👎Deprecated since 0.2.0: Use App::add_command instead.
pub fn add_command_param( self, name: impl Into<String>, flags: Option<Vec<Flag>>, description: impl Into<String>, handler: fn(&CommandContext), usage: Option<impl Into<String>>, strict_flags: bool, print_help_if_no_args: bool, subcommands: Vec<Command>, ) -> Self
Use App::add_command instead.
Registers a command from individual parameters without the Command builder.
Prefer App::add_command for most cases. This variant is useful when constructing
commands dynamically at runtime.
Sourcepub fn main(self, entry: fn(PassedFlags)) -> Self
pub fn main(self, entry: fn(PassedFlags)) -> Self
Registers a handler called when no subcommand is provided.
The handler receives a PassedFlags map containing any flags the user
passed before a subcommand. Mutually exclusive with App::print_help_if_no_args;
if both are set, this handler takes priority.
Examples found in repository?
147fn main() {
148 App::new("taskr")
149 .name("Taskr")
150 .description("A toy task manager. Demonstrates all vecli features.")
151 .version("0.1.0")
152 .main(entry)
153 .flag(
154 Flag::global("verbose")
155 .alias("v")
156 .description("Enable verbose output."),
157 )
158 .print_help_on_fail(true)
159 .add_command(
160 Command::new("add", add)
161 .description("Add a new task.")
162 .usage("<task> [--priority <level>]")
163 .flag(
164 Flag::new("priority")
165 .alias("p")
166 .description("Task priority: low, medium, or high."),
167 )
168 .strict_flags(true),
169 )
170 .add_command(
171 Command::new("list", list)
172 .description("List pending tasks.")
173 .flag(
174 Flag::new("all")
175 .alias("a")
176 .description("Include completed tasks."),
177 )
178 .subcommand(
179 Command::new("urgent", list_urgent)
180 .description("List only high-priority tasks."),
181 ),
182 )
183 .add_command(
184 Command::new("done", done)
185 .description("Mark a task as done.")
186 .usage("<task>"),
187 )
188 .add_command(
189 Command::parent("config")
190 .description("Manage taskr configuration.")
191 .print_help_if_no_args(true)
192 .subcommand(
193 Command::new("set", config_set)
194 .description("Set a config value.")
195 .usage("<key> <value>"),
196 )
197 .subcommand(Command::new("show", config_show).description("Show current config.")),
198 )
199 .add_command(Command::new("clear", clear).description("Clear all tasks."))
200 .run();
201}Sourcepub fn print_help(&self)
pub fn print_help(&self)
Prints the app-level help text to stdout.
Output includes the app name, version, description, COMMANDS listing,
OPTIONS (entry-point flags and --version), and GLOBAL FLAGS.
Sourcepub fn run(self)
pub fn run(self)
Parses std::env::args, resolves aliases, and dispatches to the matching command handler.
Handles the following built-in flags before reaching any user-defined handler:
--help/-h: prints command-specific or app-level help and exits.--version: prints the app name and version and exits.
If no subcommand is provided and a main entry point is registered, the entry
handler is called with the resolved flags. If no subcommand is found in the
registry, an error is printed and the function returns without calling any handler.
When print_help_on_fail is set, the full help listing is also printed.
Examples found in repository?
147fn main() {
148 App::new("taskr")
149 .name("Taskr")
150 .description("A toy task manager. Demonstrates all vecli features.")
151 .version("0.1.0")
152 .main(entry)
153 .flag(
154 Flag::global("verbose")
155 .alias("v")
156 .description("Enable verbose output."),
157 )
158 .print_help_on_fail(true)
159 .add_command(
160 Command::new("add", add)
161 .description("Add a new task.")
162 .usage("<task> [--priority <level>]")
163 .flag(
164 Flag::new("priority")
165 .alias("p")
166 .description("Task priority: low, medium, or high."),
167 )
168 .strict_flags(true),
169 )
170 .add_command(
171 Command::new("list", list)
172 .description("List pending tasks.")
173 .flag(
174 Flag::new("all")
175 .alias("a")
176 .description("Include completed tasks."),
177 )
178 .subcommand(
179 Command::new("urgent", list_urgent)
180 .description("List only high-priority tasks."),
181 ),
182 )
183 .add_command(
184 Command::new("done", done)
185 .description("Mark a task as done.")
186 .usage("<task>"),
187 )
188 .add_command(
189 Command::parent("config")
190 .description("Manage taskr configuration.")
191 .print_help_if_no_args(true)
192 .subcommand(
193 Command::new("set", config_set)
194 .description("Set a config value.")
195 .usage("<key> <value>"),
196 )
197 .subcommand(Command::new("show", config_show).description("Show current config.")),
198 )
199 .add_command(Command::new("clear", clear).description("Clear all tasks."))
200 .run();
201}