-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand-registration.en.html
188 lines (172 loc) · 18.8 KB
/
command-registration.en.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Command Registration — AMC Traffic Server Documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinxdoc.css" />
<link rel="stylesheet" type="text/css" href="_static/graphviz.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Testing" href="testing.en.html" />
<link rel="prev" title="Cache Tool" href="cache-tool.en.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="testing.en.html" title="Testing"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="cache-tool.en.html" title="Cache Tool"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">SWOC Docs</a> »</li>
<li class="nav-item nav-item-1"><a href="ats-projects.en.html" >Traffic Server Projects</a> »</li>
<li class="nav-item nav-item-2"><a href="cache-tool.en.html" accesskey="U">Cache Tool</a> »</li>
<li class="nav-item nav-item-this"><a href="">Command Registration</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="command-registration">
<span id="id1"></span><h1>Command Registration<a class="headerlink" href="#command-registration" title="Permalink to this headline">¶</a></h1>
<p>Command registration is registering <em>tags</em> that correspond to actions for a command line tool to execute. There is a tree of tags so that more specific commands are done by listing multiple tags. E.g. “list” and “list stripes” are different actions and each tag controls which tags are allowed to follow. For exanmple <strong class="program">traffic_ctl</strong> with commands like:</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="n">traffic_ctl</span><span class="w"> </span><span class="n">shutdown</span><span class="w"></span>
<span class="n">traffic_ctl</span><span class="w"> </span><span class="n">metric</span><span class="w"> </span><span class="n">set</span><span class="w"> </span><span class="n">proxy</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">http</span><span class="p">.</span><span class="n">cache</span><span class="p">.</span><span class="n">enable</span><span class="w"> </span><span class="mi">0</span><span class="w"></span>
</pre></div>
</div>
<p>Internally this is done in <strong class="program">traffic_ctl</strong> in an ad hoc fashion where each action is done by
invoking a function and each such function must handle dispatching to any subcommand tags. This
class is an attempt to make that generic so that action functions are leafs of command line parsing.
This reduces cut and paste code along with making the tag hieararchy controlled from the top level
of the program rather than being scattered across the implementation.</p>
</section>
<section id="implementation">
<h1>Implementation<a class="headerlink" href="#implementation" title="Permalink to this headline">¶</a></h1>
<dl class="cpp class">
<dt class="sig sig-object cpp" id="_CPPv412CommandTable">
<span id="_CPPv312CommandTable"></span><span id="_CPPv212CommandTable"></span><span id="CommandTable"></span><span class="k"><span class="pre">class</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">CommandTable</span></span></span><a class="headerlink" href="#_CPPv412CommandTable" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>The root of a set of registered commands.</p>
<dl class="cpp function">
<dt class="sig sig-object cpp" id="_CPPv4N12CommandTable12CommandTableEv">
<span id="_CPPv3N12CommandTable12CommandTableEv"></span><span id="_CPPv2N12CommandTable12CommandTableEv"></span><span id="CommandTable::CommandTable"></span><span class="sig-name descname"><span class="n"><span class="pre">CommandTable</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N12CommandTable12CommandTableEv" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Construct an empty command table.</p>
</dd></dl>
<dl class="cpp type">
<dt class="sig sig-object cpp" id="_CPPv4N12CommandTable6ActionE">
<span id="_CPPv3N12CommandTable6ActionE"></span><span id="_CPPv2N12CommandTable6ActionE"></span><span class="k"><span class="pre">using</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Action</span></span></span><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><a class="reference internal" href="external-types.en.html#_CPPv4St" title="std"><span class="n"><span class="pre">std</span></span></a><span class="p"><span class="pre">::</span></span><a class="reference internal" href="external-types.en.html#_CPPv4I0ENSt8functionE" title="std::function"><span class="n"><span class="pre">function</span></span></a><span class="p"><span class="pre"><</span></span><a class="reference internal" href="external-types.en.html#_CPPv42ts" title="ts"><span class="n"><span class="pre">ts</span></span></a><span class="p"><span class="pre">::</span></span><a class="reference internal" href="external-types.en.html#_CPPv4N2ts6ErrataE" title="ts::Errata"><span class="n"><span class="pre">Errata</span></span></a><span class="p"><span class="pre">(</span></span><span class="kt"><span class="pre">int</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">[</span></span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">)</span></span><span class="p"><span class="pre">></span></span><a class="headerlink" href="#_CPPv4N12CommandTable6ActionE" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>A function that performs the action for a command. This action is always a leaf, any
additional arguments available are passeed to the function rather than checked for additional
commands. The first argument to the function will be the number of arguments and the second an
array of constant character pointers that are the arguments.</p>
</dd></dl>
<dl class="cpp type">
<dt class="sig sig-object cpp" id="_CPPv4N12CommandTable13NullaryActionE">
<span id="_CPPv3N12CommandTable13NullaryActionE"></span><span id="_CPPv2N12CommandTable13NullaryActionE"></span><span class="k"><span class="pre">using</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">NullaryAction</span></span></span><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><a class="reference internal" href="external-types.en.html#_CPPv4St" title="std"><span class="n"><span class="pre">std</span></span></a><span class="p"><span class="pre">::</span></span><a class="reference internal" href="external-types.en.html#_CPPv4I0ENSt8functionE" title="std::function"><span class="n"><span class="pre">function</span></span></a><span class="p"><span class="pre"><</span></span><a class="reference internal" href="external-types.en.html#_CPPv42ts" title="ts"><span class="n"><span class="pre">ts</span></span></a><span class="p"><span class="pre">::</span></span><a class="reference internal" href="external-types.en.html#_CPPv4N2ts6ErrataE" title="ts::Errata"><span class="n"><span class="pre">Errata</span></span></a><span class="p"><span class="pre">(</span></span><span class="p"><span class="pre">)</span></span><span class="p"><span class="pre">></span></span><a class="headerlink" href="#_CPPv4N12CommandTable13NullaryActionE" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>A function that performs an action for a command. This action can be used on a non-terminal
command but can take no arguments. It will be invoked only if no more arguments remain after
processing the tag for the command.</p>
</dd></dl>
<dl class="cpp class">
<dt class="sig sig-object cpp" id="_CPPv4N12CommandTable7CommandE">
<span id="_CPPv3N12CommandTable7CommandE"></span><span id="_CPPv2N12CommandTable7CommandE"></span><span id="CommandTable::Command"></span><span class="k"><span class="pre">class</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Command</span></span></span><a class="headerlink" href="#_CPPv4N12CommandTable7CommandE" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>An command action.</p>
<dl class="cpp function">
<dt class="sig sig-object cpp" id="_CPPv4N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE">
<span id="_CPPv3N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE"></span><span id="_CPPv2N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE"></span><span id="CommandTable::Command::subCommand__ssCR.ssCR"></span><span class="sig-name descname"><span class="n"><span class="pre">subCommand</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#_CPPv4St" title="std"><span class="n"><span class="pre">std</span></span></a><span class="p"><span class="pre">::</span></span><a class="reference internal" href="external-types.en.html#_CPPv4NSt6stringE" title="std::string"><span class="n"><span class="pre">string</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">&</span></span><span class="n sig-param"><span class="pre">name</span></span>, <a class="reference internal" href="external-types.en.html#_CPPv4St" title="std"><span class="n"><span class="pre">std</span></span></a><span class="p"><span class="pre">::</span></span><a class="reference internal" href="external-types.en.html#_CPPv4NSt6stringE" title="std::string"><span class="n"><span class="pre">string</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">&</span></span><span class="n sig-param"><span class="pre">help</span></span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Add a subcommand to this command. The tag used is <em>name</em> along with a <em>help</em> string for diagnostics.</p>
</dd></dl>
<dl class="cpp function">
<dt class="sig sig-object cpp" id="_CPPv4N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE6Action">
<span id="_CPPv3N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE6Action"></span><span id="_CPPv2N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE6Action"></span><span id="CommandTable::Command::subCommand__ssCR.ssCR.Action"></span><span class="sig-name descname"><span class="n"><span class="pre">subCommand</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#_CPPv4St" title="std"><span class="n"><span class="pre">std</span></span></a><span class="p"><span class="pre">::</span></span><a class="reference internal" href="external-types.en.html#_CPPv4NSt6stringE" title="std::string"><span class="n"><span class="pre">string</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">&</span></span><span class="n sig-param"><span class="pre">name</span></span>, <a class="reference internal" href="external-types.en.html#_CPPv4St" title="std"><span class="n"><span class="pre">std</span></span></a><span class="p"><span class="pre">::</span></span><a class="reference internal" href="external-types.en.html#_CPPv4NSt6stringE" title="std::string"><span class="n"><span class="pre">string</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">&</span></span><span class="n sig-param"><span class="pre">help</span></span>, <a class="reference internal" href="#_CPPv4N12CommandTable6ActionE" title="CommandTable::Action"><span class="n"><span class="pre">Action</span></span></a><span class="w"> </span><span class="n sig-param"><span class="pre">f</span></span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE6Action" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Add a subcommand to this command. The tag will be <em>name</em>. Help for this command
will be <em>help</em>. If the command is invoked the function <em>f</em> will be called.
This will be a leaf tag meaning that if this tag is reached no more subcommands will be
accessible and additional arguments will be passed to <em>f</em>.</p>
</dd></dl>
<dl class="cpp function">
<dt class="sig sig-object cpp" id="_CPPv4N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE13NullaryAction">
<span id="_CPPv3N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE13NullaryAction"></span><span id="_CPPv2N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE13NullaryAction"></span><span id="CommandTable::Command::subCommand__ssCR.ssCR.NullaryAction"></span><span class="sig-name descname"><span class="n"><span class="pre">subCommand</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#_CPPv4St" title="std"><span class="n"><span class="pre">std</span></span></a><span class="p"><span class="pre">::</span></span><a class="reference internal" href="external-types.en.html#_CPPv4NSt6stringE" title="std::string"><span class="n"><span class="pre">string</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">&</span></span><span class="n sig-param"><span class="pre">name</span></span>, <a class="reference internal" href="external-types.en.html#_CPPv4St" title="std"><span class="n"><span class="pre">std</span></span></a><span class="p"><span class="pre">::</span></span><a class="reference internal" href="external-types.en.html#_CPPv4NSt6stringE" title="std::string"><span class="n"><span class="pre">string</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">&</span></span><span class="n sig-param"><span class="pre">help</span></span>, <a class="reference internal" href="#_CPPv4N12CommandTable13NullaryActionE" title="CommandTable::NullaryAction"><span class="n"><span class="pre">NullaryAction</span></span></a><span class="w"> </span><span class="n sig-param"><span class="pre">f</span></span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N12CommandTable7Command10subCommandERKNSt6stringERKNSt6stringE13NullaryAction" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Add a subcommand to this command. The tag will be <em>name</em>. Help for this command
will be <em>help</em>. If the command is invoked the function <em>f</em> will be called.
This command will only be invoked if no more arguments are available, otherwise the
additional arguments will be treated as subcommand tags.</p>
</dd></dl>
</dd></dl>
</dd></dl>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="index.html">
<img class="logo" src="_static/balcora-gate-400x400.jpg" alt="Logo"/>
</a></p>
<h3><a href="index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Command Registration</a></li>
<li><a class="reference internal" href="#implementation">Implementation</a></li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="cache-tool.en.html"
title="previous chapter">Cache Tool</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="testing.en.html"
title="next chapter">Testing</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/command-registration.en.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="testing.en.html" title="Testing"
>next</a> |</li>
<li class="right" >
<a href="cache-tool.en.html" title="Cache Tool"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">SWOC Docs</a> »</li>
<li class="nav-item nav-item-1"><a href="ats-projects.en.html" >Traffic Server Projects</a> »</li>
<li class="nav-item nav-item-2"><a href="cache-tool.en.html" >Cache Tool</a> »</li>
<li class="nav-item nav-item-this"><a href="">Command Registration</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2017, [email protected].
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
</div>
</body>
</html>