Files
cligen/docs/CliGen/Command.html
T

767 lines
24 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Crystal Docs 1.20.3">
<meta name="crystal_docs.project_version" content="object_rework-dev">
<meta name="crystal_docs.project_name" content="CliGenerator">
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/doc.js"></script>
<meta name="repository-name" content="CliGenerator">
<title>CliGen::Command - CliGenerator object_rework-dev</title>
<script type="text/javascript">
CrystalDocs.base_path = "../";
</script>
</head>
<body>
<svg class="hidden">
<symbol id="octicon-link" viewBox="0 0 16 16">
<path fill="currentColor" fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path>
</symbol>
</svg>
<input type="checkbox" id="sidebar-btn">
<label for="sidebar-btn" id="sidebar-btn-label">
<svg class="open" xmlns="http://www.w3.org/2000/svg" height="2em" width="2em" viewBox="0 0 512 512"><title>Open Sidebar</title><path fill="currentColor" d="M80 96v64h352V96H80zm0 112v64h352v-64H80zm0 112v64h352v-64H80z"></path></svg>
<svg class="close" xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" viewBox="0 0 512 512"><title>Close Sidebar</title><path fill="currentColor" d="m118.6 73.4-45.2 45.2L210.7 256 73.4 393.4l45.2 45.2L256 301.3l137.4 137.3 45.2-45.2L301.3 256l137.3-137.4-45.2-45.2L256 210.7Z"></path></svg>
</label>
<div class="sidebar">
<div class="sidebar-header">
<div class="search-box">
<input type="search" class="search-input" placeholder="Search..." spellcheck="false" aria-label="Search">
</div>
<div class="project-summary">
<h1 class="project-name">
<a href="../index.html">
CliGenerator
</a>
</h1>
<span class="project-version">
object_rework-dev
</span>
</div>
</div>
<div class="search-results hidden">
<ul class="search-list"></ul>
</div>
<div class="types-list">
<ul>
<li class="parent open current" data-id="CliGenerator/CliGen" data-name="cligen">
<a href="../CliGen.html">CliGen</a>
<ul>
<li class=" " data-id="CliGenerator/CliGen/App" data-name="cligen::app">
<a href="../CliGen/App.html">App</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/Arg" data-name="cligen::arg">
<a href="../CliGen/Arg.html">Arg</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/ArgReprocessedError" data-name="cligen::argreprocessederror">
<a href="../CliGen/ArgReprocessedError.html">ArgReprocessedError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/Argument" data-name="cligen::argument">
<a href="../CliGen/Argument.html">Argument</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/BaseCommandNode" data-name="cligen::basecommandnode">
<a href="../CliGen/BaseCommandNode.html">BaseCommandNode</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/BaseFlag" data-name="cligen::baseflag">
<a href="../CliGen/BaseFlag.html">BaseFlag</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/Coercable" data-name="cligen::coercable">
<a href="../CliGen/Coercable.html">Coercable</a>
</li>
<li class=" current" data-id="CliGenerator/CliGen/Command" data-name="cligen::command">
<a href="../CliGen/Command.html">Command</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/CommandInfo" data-name="cligen::commandinfo">
<a href="../CliGen/CommandInfo.html">CommandInfo</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/CommandMeta" data-name="cligen::commandmeta">
<a href="../CliGen/CommandMeta.html">CommandMeta</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/CommandNode" data-name="cligen::commandnode(t)">
<a href="../CliGen/CommandNode.html">CommandNode</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/Common" data-name="cligen::common">
<a href="../CliGen/Common.html">Common</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/ConfigurationError" data-name="cligen::configurationerror">
<a href="../CliGen/ConfigurationError.html">ConfigurationError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/DuplicateCommandError" data-name="cligen::duplicatecommanderror">
<a href="../CliGen/DuplicateCommandError.html">DuplicateCommandError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/DuplicateFlagError" data-name="cligen::duplicateflagerror">
<a href="../CliGen/DuplicateFlagError.html">DuplicateFlagError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/Error" data-name="cligen::error">
<a href="../CliGen/Error.html">Error</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/Flag" data-name="cligen::flag(t)">
<a href="../CliGen/Flag.html">Flag</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/FlagArgumentError" data-name="cligen::flagargumenterror">
<a href="../CliGen/FlagArgumentError.html">FlagArgumentError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/FlagBundleError" data-name="cligen::flagbundleerror">
<a href="../CliGen/FlagBundleError.html">FlagBundleError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/FlagMeta" data-name="cligen::flagmeta">
<a href="../CliGen/FlagMeta.html">FlagMeta</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/FlagMissingArgumentError" data-name="cligen::flagmissingargumenterror">
<a href="../CliGen/FlagMissingArgumentError.html">FlagMissingArgumentError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/FlagNotFoundError" data-name="cligen::flagnotfounderror">
<a href="../CliGen/FlagNotFoundError.html">FlagNotFoundError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/Format" data-name="cligen::format">
<a href="../CliGen/Format.html">Format</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/HelpRequestedError" data-name="cligen::helprequestederror">
<a href="../CliGen/HelpRequestedError.html">HelpRequestedError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/InternalError" data-name="cligen::internalerror">
<a href="../CliGen/InternalError.html">InternalError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/InternalVar" data-name="cligen::internalvar">
<a href="../CliGen/InternalVar.html">InternalVar</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/InvalidFlagValueError" data-name="cligen::invalidflagvalueerror">
<a href="../CliGen/InvalidFlagValueError.html">InvalidFlagValueError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/InvalidOptionError" data-name="cligen::invalidoptionerror">
<a href="../CliGen/InvalidOptionError.html">InvalidOptionError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/MatchType" data-name="cligen::matchtype">
<a href="../CliGen/MatchType.html">MatchType</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/MissingDispatchError" data-name="cligen::missingdispatcherror">
<a href="../CliGen/MissingDispatchError.html">MissingDispatchError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/MissingRequiredFlagError" data-name="cligen::missingrequiredflagerror">
<a href="../CliGen/MissingRequiredFlagError.html">MissingRequiredFlagError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/Parsable" data-name="cligen::parsable">
<a href="../CliGen/Parsable.html">Parsable</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/ParseableInvariantError" data-name="cligen::parseableinvarianterror">
<a href="../CliGen/ParseableInvariantError.html">ParseableInvariantError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/PreRunCommand" data-name="cligen::preruncommand">
<a href="../CliGen/PreRunCommand.html">PreRunCommand</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/ProxyCommand" data-name="cligen::proxycommand">
<a href="../CliGen/ProxyCommand.html">ProxyCommand</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/Regex" data-name="cligen::regex">
<a href="../CliGen/Regex.html">Regex</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/RegexInvariantError" data-name="cligen::regexinvarianterror">
<a href="../CliGen/RegexInvariantError.html">RegexInvariantError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/ReservedFlagError" data-name="cligen::reservedflagerror">
<a href="../CliGen/ReservedFlagError.html">ReservedFlagError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/RunCommand" data-name="cligen::runcommand">
<a href="../CliGen/RunCommand.html">RunCommand</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/RuntimeError" data-name="cligen::runtimeerror">
<a href="../CliGen/RuntimeError.html">RuntimeError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/SubCommand" data-name="cligen::subcommand">
<a href="../CliGen/SubCommand.html">SubCommand</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/SubCommandInfo" data-name="cligen::subcommandinfo">
<a href="../CliGen/SubCommandInfo.html">SubCommandInfo</a>
</li>
<li class="parent " data-id="CliGenerator/CliGen/Timeparse" data-name="cligen::timeparse">
<a href="../CliGen/Timeparse.html">Timeparse</a>
<ul>
<li class=" " data-id="CliGenerator/CliGen/Timeparse/OperationUnit" data-name="cligen::timeparse::operationunit">
<a href="../CliGen/Timeparse/OperationUnit.html">OperationUnit</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/Timeparse/RelativeOperation" data-name="cligen::timeparse::relativeoperation">
<a href="../CliGen/Timeparse/RelativeOperation.html">RelativeOperation</a>
</li>
</ul>
</li>
<li class=" " data-id="CliGenerator/CliGen/TimeParseError" data-name="cligen::timeparseerror">
<a href="../CliGen/TimeParseError.html">TimeParseError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/Trigger" data-name="cligen::trigger">
<a href="../CliGen/Trigger.html">Trigger</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/UnknownCommandNodeError" data-name="cligen::unknowncommandnodeerror">
<a href="../CliGen/UnknownCommandNodeError.html">UnknownCommandNodeError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/UnknownFlagError" data-name="cligen::unknownflagerror">
<a href="../CliGen/UnknownFlagError.html">UnknownFlagError</a>
</li>
<li class=" " data-id="CliGenerator/CliGen/ValidationError" data-name="cligen::validationerror">
<a href="../CliGen/ValidationError.html">ValidationError</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="main-content">
<h1 class="type-name">
<span class="kind">
class
</span> CliGen::<wbr>Command
</h1>
<ul class="superclass-hierarchy"><li class="superclass"><a href="../CliGen/Command.html">CliGen::Command</a></li><li class="superclass">Reference</li><li class="superclass">Object</li></ul>
<h2>
<a id="defined-in" class="anchor" href="#defined-in">
<svg class="octicon-link" aria-hidden="true">
<use href="#octicon-link"/>
</svg>
</a>
Defined in:
</h2>
cligen/command.cr
<br/>
cligen/command/argument.cr
<br/>
cligen/command/define_command_initializer.cr
<br/>
cligen/command/define_singleton_init.cr
<br/>
cligen/command/generate_gather_handler.cr
<br/>
cligen/command/generate_register_command.cr
<br/>
cligen/command/help_template.cr
<br/>
cligen/command/resolve_value.cr
<br/>
cligen/command/subcommand.cr
<br/>
cligen/command/validate_command_tree.cr
<br/>
<h2>
<a id="macro-summary" class="anchor" href="#macro-summary">
<svg class="octicon-link" aria-hidden="true">
<use href="#octicon-link"/>
</svg>
</a>
Macro Summary
</h2>
<ul class="list-summary">
<li class="entry-summary">
<a href="#argument%28variable%2Cdescription%2Clong%3Dnil%2Cshort%3Dnil%2Cvalidation%3Dnil%2Con_match%3Dnil%2Cdef_setter%3Dfalse%2Cdef_getter%3Dfalse%2Coptions%3Dnil%2Cdelimiter%3D%22%2C%22%2Cformat%3Dnil%2Callow_no_verification%3Dfalse%2Cenv_var%3D%22%22%29-macro" class="signature"><strong>argument</strong>(variable, description, long = <span class="n">nil</span>, short = <span class="n">nil</span>, validation = <span class="n">nil</span>, on_match = <span class="n">nil</span>, def_setter = <span class="n">false</span>, def_getter = <span class="n">false</span>, options = <span class="n">nil</span>, delimiter = <span class="s">&quot;,&quot;</span>, format = <span class="n">nil</span>, allow_no_verification = <span class="n">false</span>, env_var = <span class="s">&quot;&quot;</span>)</a>
</li>
<li class="entry-summary">
<a href="#define_command_initializer-macro" class="signature"><strong>define_command_initializer</strong></a>
</li>
<li class="entry-summary">
<a href="#define_singleton_init-macro" class="signature"><strong>define_singleton_init</strong></a>
<div class="summary"><p>This macro simply provides a easy singleton initializer for your command to allow for you do (if this class isn't the target of a command) to still be able to gather a Command object without having to have it as the target.</p></div>
</li>
<li class="entry-summary">
<a href="#generate_gather_handler-macro" class="signature"><strong>generate_gather_handler</strong></a>
</li>
<li class="entry-summary">
<a href="#generate_register_command-macro" class="signature"><strong>generate_register_command</strong></a>
</li>
<li class="entry-summary">
<a href="#help_template%28filepath%29-macro" class="signature"><strong>help_template</strong>(filepath)</a>
</li>
<li class="entry-summary">
<a href="#resolve_value%28variable%2C%2A%2Cdefault%3Dnil%29-macro" class="signature"><strong>resolve_value</strong>(variable, *, default = <span class="n">nil</span>)</a>
<div class="summary"><p>This macro is just meant to provide the user an ability to resolve instance var/varibles from parent commands.</p></div>
</li>
<li class="entry-summary">
<a href="#subcommand%28func%2Cdescription%2Cexamples%3Dnil%2C%26block%29-macro" class="signature"><strong>subcommand</strong>(func, description, examples = <span class="n">nil</span>, &block)</a>
</li>
<li class="entry-summary">
<a href="#validate_command_tree-macro" class="signature"><strong>validate_command_tree</strong></a>
<div class="summary"><p>This macro serves as a compile-time checker of the command-tree to validate that there is no recursive references of the command-list that would possibly cause a recursive stack-overflow during App.generate when App begins registering all user defined commands.</p></div>
</li>
</ul>
<h2>
<a id="instance-method-summary" class="anchor" href="#instance-method-summary">
<svg class="octicon-link" aria-hidden="true">
<use href="#octicon-link"/>
</svg>
</a>
Instance Method Summary
</h2>
<ul class="list-summary">
<li class="entry-summary">
<a href="#handler%3F%3ABool-instance-method" class="signature"><strong>#handler?</strong> : Bool</a>
</li>
</ul>
<div class="methods-inherited">
</div>
<h2>
<a id="macro-detail" class="anchor" href="#macro-detail">
<svg class="octicon-link" aria-hidden="true">
<use href="#octicon-link"/>
</svg>
</a>
Macro Detail
</h2>
<div class="entry-detail" id="argument(variable,description,long=nil,short=nil,validation=nil,on_match=nil,def_setter=false,def_getter=false,options=nil,delimiter=&quot;,&quot;,format=nil,allow_no_verification=false,env_var=&quot;&quot;)-macro">
<div class="signature">
macro <strong>argument</strong>(variable, description, long = <span class="n">nil</span>, short = <span class="n">nil</span>, validation = <span class="n">nil</span>, on_match = <span class="n">nil</span>, def_setter = <span class="n">false</span>, def_getter = <span class="n">false</span>, options = <span class="n">nil</span>, delimiter = <span class="s">&quot;,&quot;</span>, format = <span class="n">nil</span>, allow_no_verification = <span class="n">false</span>, env_var = <span class="s">&quot;&quot;</span>)
<a class="method-permalink" href="#argument%28variable%2Cdescription%2Clong%3Dnil%2Cshort%3Dnil%2Cvalidation%3Dnil%2Con_match%3Dnil%2Cdef_setter%3Dfalse%2Cdef_getter%3Dfalse%2Coptions%3Dnil%2Cdelimiter%3D%22%2C%22%2Cformat%3Dnil%2Callow_no_verification%3Dfalse%2Cenv_var%3D%22%22%29-macro">#</a>
</div>
<br/>
<div>
</div>
</div>
<div class="entry-detail" id="define_command_initializer-macro">
<div class="signature">
macro <strong>define_command_initializer</strong>
<a class="method-permalink" href="#define_command_initializer-macro">#</a>
</div>
<br/>
<div>
</div>
</div>
<div class="entry-detail" id="define_singleton_init-macro">
<div class="signature">
macro <strong>define_singleton_init</strong>
<a class="method-permalink" href="#define_singleton_init-macro">#</a>
</div>
<div class="doc">
<p>This macro simply provides a easy singleton initializer for your command
to allow for you do (if this class isn't the target of a command) to still
be able to gather a Command object without having to have it as the target.</p>
<p>This will setup the default (no args) initializer to gather the handler from
CliGen::App and then resolve all of the ivar (CliGen managed) to the parsed
values from the associated Flag(T) object that (if the process itself is
being started by CliGen the provided flags will store the value to be
set here)</p>
</div>
<br/>
<div>
</div>
</div>
<div class="entry-detail" id="generate_gather_handler-macro">
<div class="signature">
macro <strong>generate_gather_handler</strong>
<a class="method-permalink" href="#generate_gather_handler-macro">#</a>
</div>
<br/>
<div>
</div>
</div>
<div class="entry-detail" id="generate_register_command-macro">
<div class="signature">
macro <strong>generate_register_command</strong>
<a class="method-permalink" href="#generate_register_command-macro">#</a>
</div>
<br/>
<div>
</div>
</div>
<div class="entry-detail" id="help_template(filepath)-macro">
<div class="signature">
macro <strong>help_template</strong>(filepath)
<a class="method-permalink" href="#help_template%28filepath%29-macro">#</a>
</div>
<br/>
<div>
</div>
</div>
<div class="entry-detail" id="resolve_value(variable,*,default=nil)-macro">
<div class="signature">
macro <strong>resolve_value</strong>(variable, *, default = <span class="n">nil</span>)
<a class="method-permalink" href="#resolve_value%28variable%2C%2A%2Cdefault%3Dnil%29-macro">#</a>
</div>
<div class="doc">
<p>This macro is just meant to provide the user an ability to resolve instance
var/varibles from parent commands. Simply to allow subcommands to be able
to retrieve values from their parents</p>
<p>As an aside, this (as written) can only be used for variables that have
a default defined (ex: @var : Int32 = 3)</p>
<p>For variables that (in your parent class) isn't set with a default value,
you will need to provide the (default: <val>) kwarg to set your own
runtime default if the value itself cannot be ensured by the compiler.</p>
<p>This is a requirement as this macro MUST always return a value without
rasing, and the only way to do that is force the user to provide a
default of their choosing.</p>
</div>
<br/>
<div>
</div>
</div>
<div class="entry-detail" id="subcommand(func,description,examples=nil,&amp;block)-macro">
<div class="signature">
macro <strong>subcommand</strong>(func, description, examples = <span class="n">nil</span>, &block)
<a class="method-permalink" href="#subcommand%28func%2Cdescription%2Cexamples%3Dnil%2C%26block%29-macro">#</a>
</div>
<br/>
<div>
</div>
</div>
<div class="entry-detail" id="validate_command_tree-macro">
<div class="signature">
macro <strong>validate_command_tree</strong>
<a class="method-permalink" href="#validate_command_tree-macro">#</a>
</div>
<div class="doc">
<p>This macro serves as a compile-time checker of the command-tree to
validate that there is no recursive references of the command-list
that would possibly cause a recursive stack-overflow during App.generate
when App begins registering all user defined commands.</p>
<p>However, while this does exist, due to the way that the App.generate method
handles gathering root commands it makes this edge-case impossible to hit
aside from manually running the
Command#register_command([] of CliGen::Command) method.</p>
<p>However, with this in place this issue cannot be hit at runtime as this will
prevent compilation if a recursive/circular command tree exists.</p>
<p>Additionally, this exists to prevent the user from defining a command tree
that extends past the compile-time configured max via the
CliGen::MAX_COMMAND_DEPTH constant.</p>
<p>The reason this is a thing is because crystal macros don't allow for
unbounded while's/until's in macros, meaning it always has to be
deterministic. SO to deal with this and still allow for subcommand
defining you need either go with the default (32 command depth) or
define your own larger max (understand this will affect compile-time
due to this directly affecting loops in the Command macros).</p>
</div>
<br/>
<div>
</div>
</div>
<h2>
<a id="instance-method-detail" class="anchor" href="#instance-method-detail">
<svg class="octicon-link" aria-hidden="true">
<use href="#octicon-link"/>
</svg>
</a>
Instance Method Detail
</h2>
<div class="entry-detail" id="handler?:Bool-instance-method">
<div class="signature">
def <strong>handler?</strong> : Bool
<a class="method-permalink" href="#handler%3F%3ABool-instance-method">#</a>
</div>
<br/>
<div>
</div>
</div>
</div>
</body>
</html>