pub struct Command {
pub name: String,
pub action: Option<Action>,
pub authors: String,
pub copyright: String,
pub license: License,
pub description: Option<String>,
pub usage: String,
pub l_flags: Vector<Flag>,
pub c_flags: Vector<Flag>,
pub alias: Vector<String>,
pub version: String,
pub sub: Vector<Command>,
}
Expand description
The struct for command information store and command execution This can be root and edge コマンドの情報格納&実行用構造体です。root(根)にもedge(葉)にもなりえます。
Fields
name: String
Command name
action: Option<Action>
Command action
Command authors
copyright: String
Command copyright
license: License
License of command
description: Option<String>
Command description
usage: String
Command usage
l_flags: Vector<Flag>
local flags of command
c_flags: Vector<Flag>
common flags of command
alias: Vector<String>
alias for command
version: String
Command version
sub: Vector<Command>
container of sub-command
Implementations
sourceimpl Command
impl Command
sourcepub fn with_base<T: Into<String>>(
name: T,
authors: T,
version: T,
description: T,
action: Option<Action>
) -> Command
pub fn with_base<T: Into<String>>(
name: T,
authors: T,
version: T,
description: T,
action: Option<Action>
) -> Command
Create new instance of Command with name,authors,version
sourcepub fn with_all_field(
name: String,
action: Option<Action>,
authors: String,
copyright: String,
license: License,
description: Option<String>,
usage: String,
local_flags: Vector<Flag>,
common_flags: Vector<Flag>,
alias: Vector<String>,
version: String,
sub: Vector<Command>
) -> Command
pub fn with_all_field(
name: String,
action: Option<Action>,
authors: String,
copyright: String,
license: License,
description: Option<String>,
usage: String,
local_flags: Vector<Flag>,
common_flags: Vector<Flag>,
alias: Vector<String>,
version: String,
sub: Vector<Command>
) -> Command
Create new instance of Command with more options
sourcepub fn run_with_auto_arg_collect(self) -> Result<ActionResult, ActionError>
pub fn run_with_auto_arg_collect(self) -> Result<ActionResult, ActionError>
Run command with collecting args automatically
sourcepub fn single_run(
self,
raw_args: Vec<String>
) -> Result<ActionResult, ActionError>
pub fn single_run(
self,
raw_args: Vec<String>
) -> Result<ActionResult, ActionError>
Run command as single(do not have sub) command ルートからサブコマンドがないシンプルな状態の時 アクションが登録されていなければサブコマンドがあるかを調査する
Set command’s authors
sourcepub fn local_flag(self, flag: Flag) -> Self
pub fn local_flag(self, flag: Flag) -> Self
Add a local flag to command
sourcepub fn local_flags(self, flags: Vec<Flag>) -> Self
pub fn local_flags(self, flags: Vec<Flag>) -> Self
Add a local flags to command
sourcepub fn common_flag(self, flag: Flag) -> Self
pub fn common_flag(self, flag: Flag) -> Self
Add a common flag to command
sourcepub fn command_flags(self, flags: Vec<Flag>) -> Self
pub fn command_flags(self, flags: Vec<Flag>) -> Self
Add a common flag to command
sourcepub fn description<T: Into<String>>(self, description: T) -> Self
pub fn description<T: Into<String>>(self, description: T) -> Self
Set command’s description
sourcepub fn sub_command(self, sub_command: Command) -> Self
pub fn sub_command(self, sub_command: Command) -> Self
Add command’s sub command
sourcepub fn sub_commands(self, sub_commands: Vec<Command>) -> Self
pub fn sub_commands(self, sub_commands: Vec<Command>) -> Self
Add sub commands
sourcepub fn is(&self, name_or_alias: &str) -> bool
pub fn is(&self, name_or_alias: &str) -> bool
Returns true if name_or_alias matches command’s name or one of alias at least name_or_aliasがコマンド名かエイリアスのうち少なくとも一つにマッチした場合trueを返す
sourcepub fn take_sub(&mut self, name_or_alias: &str) -> Option<Command>
pub fn take_sub(&mut self, name_or_alias: &str) -> Option<Command>
Take sub command matches name_or_alias. name_or_aliasに一致するサブコマンドがある場合、保持しているVectorからswap_removeで取り出して返す
sourcepub fn get_mut_sub(&mut self, name_or_alias: &str) -> Option<&mut Command>
pub fn get_mut_sub(&mut self, name_or_alias: &str) -> Option<&mut Command>
Gets sub command mutable reference matches name_or_alias.
sourcepub fn derive_route_init_vector(&self) -> Vector<String>
pub fn derive_route_init_vector(&self) -> Vector<String>
Returns init Vector for Context’s route
sourceimpl Command
impl Command
sourcepub fn run_from_args(
self,
raw_args: Vec<String>
) -> Result<ActionResult, ActionError>
pub fn run_from_args(
self,
raw_args: Vec<String>
) -> Result<ActionResult, ActionError>
Run commands with raw_args
sourcepub fn run_with_context(
self,
context: Context
) -> Result<ActionResult, ActionError>
pub fn run_with_context(
self,
context: Context
) -> Result<ActionResult, ActionError>
Run command with context
sourcepub fn assign_context(
self,
c: Context,
p: Parser,
inter_mediate_args: VecDeque<MiddleArg>,
last: MiddleArg
) -> Result<ActionResult, ActionError>
pub fn assign_context(
self,
c: Context,
p: Parser,
inter_mediate_args: VecDeque<MiddleArg>,
last: MiddleArg
) -> Result<ActionResult, ActionError>
Assign context to sub command or self own action. コンテキストのargsを見てもサブコマンド行きかコマンドでそのまま処理すればいいか分からなかった時の処理用
sourcepub fn assign_run(
self,
args: VecDeque<String>,
inter_mediate_args: VecDeque<MiddleArg>,
p: Parser,
raw_args: Vec<String>,
exe_path: String,
last: MiddleArg
) -> Result<ActionResult, ActionError>
pub fn assign_run(
self,
args: VecDeque<String>,
inter_mediate_args: VecDeque<MiddleArg>,
p: Parser,
raw_args: Vec<String>,
exe_path: String,
last: MiddleArg
) -> Result<ActionResult, ActionError>
Assign subcomannd’s run or command’s own action with no context コンテキストが生成されていないときに、run_from_args内で第一引数からサブコマンドかそうでないか分からなかった時に再帰処理を行って割り当てを行う関数
sourcepub fn handle_sub_result(
self,
req: Result<ActionResult, ActionError>
) -> Result<ActionResult, ActionError>
pub fn handle_sub_result(
self,
req: Result<ActionResult, ActionError>
) -> Result<ActionResult, ActionError>
Handle sub action’s result (Result<ActionResult, ActionError>). Implemented: at ParentActionRequest and Err アクションの結果であるResult<ActionResult, ActionError>をハンドルする関数。現在はParentActionRequestのハンドリング、もしくはエラー表示のみ