Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: src/site/docs/tutorials/cmdline/index.markdown

Issue 275613002: Update polymer tutorial; make directory paths match new sample structure (Closed) Base URL: https://github.com/dart-lang/dartlang.org.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 --- 1 ---
2 layout: tutorial 2 layout: tutorial
3 title: "Write Command-Line Apps" 3 title: "Write Command-Line Apps"
4 description: "Basics for command-line apps" 4 description: "Basics for command-line apps"
5 has-permalinks: true 5 has-permalinks: true
6 tutorial: 6 tutorial:
7 id: dart-io 7 id: dart-io
8 next: httpserver 8 next: httpserver
9 next-title: "Write HTTP Clients & Servers" 9 next-title: "Write HTTP Clients & Servers"
10 prev: indexeddb/ 10 prev: indexeddb/
11 prev-title: "Use IndexedDB" 11 prev-title: "Use IndexedDB"
12 --- 12 ---
13 13
14 {% capture whats_the_point %} 14 {% capture whats_the_point %}
15 15
16 * Command-line applications need to do input and output. 16 * Command-line applications need to do input and output.
17 * The dart:io library provides I/O functionality. 17 * The dart:io library provides I/O functionality.
18 * The args package helps define and parse command-line arguments. 18 * The args package helps define and parse command-line arguments.
19 * Most input and output requires the use of Streams. 19 * Most input and output requires the use of Streams.
20 * Streams provide a series of asynchronous data events. 20 * Streams provide a series of asynchronous data events.
21 * To handle asynchronous data, you need to use Futures. 21 * To handle asynchronous data, you need to use Futures.
22 22
23 {% endcapture %} 23 {% endcapture %}
24 24
25 {% capture sample_links %} 25 {% capture sample_links %}
26 26
27 <p> This tutorial features these examples:</p> 27 <p> This tutorial features the following example
28 * helloworld 28 under the `cmdline` directory:</p>
29 * dcat 29 * dcat.dart
30 30
31 <p> 31 <p>
32 Don't have the source code? 32 Don't have the source code?
33 <a href="https://github.com/dart-lang/dart-tutorials-samples/archive/master.zip" > 33 <a href="https://github.com/dart-lang/dart-tutorials-samples/archive/master.zip" >
34 Download it. 34 Download it.
35 </a> 35 </a>
36 36
37 {% endcapture %} 37 {% endcapture %}
38 38
39 {% capture content %} 39 {% capture content %}
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 | <a href="https://api.dartlang.org/args/ArgParser" target="_blank">ArgParser</a > | A class that parses command-line arguments | 197 | <a href="https://api.dartlang.org/args/ArgParser" target="_blank">ArgParser</a > | A class that parses command-line arguments |
198 | <a href="https://api.dartlang.org/args/ArgResults" target="_blank">ArgResults< /a> | The result of parsing command-line arguments using ArgParser. | 198 | <a href="https://api.dartlang.org/args/ArgResults" target="_blank">ArgResults< /a> | The result of parsing command-line arguments using ArgParser. |
199 {: .table } 199 {: .table }
200 200
201 Let's take a look at the `dcat` sample, 201 Let's take a look at the `dcat` sample,
202 which uses ArgParser and ArgResults to parse and store its command-line argument s. 202 which uses ArgParser and ArgResults to parse and store its command-line argument s.
203 203
204 <ol> 204 <ol>
205 <li markdown="1"> 205 <li markdown="1">
206 Copy the sample file from the github repo: 206 Copy the sample file from the github repo:
207 <a href="https://github.com/dart-lang/dart-tutorials-samples/blob/master/bin/cmd line/dcat.dart">dcat.dart</a>. 207 <a href="https://github.com/dart-lang/dart-tutorials-samples/blob/master/cmdline /bin/dcat.dart">dcat.dart</a>.
208 </li> 208 </li>
209 209
210 <li markdown="1"> 210 <li markdown="1">
211 Run the program from the command line as shown by the highlighted text. 211 Run the program from the command line as shown by the **boldface** text.
212 212
213 {% prettify bash %} 213 <pre>
214 $ [[highlight]]dart dcat.dart -n quotes.txt[[/highlight]] 214 $ <b>dart dcat.dart -n quotes.txt</b>
215 1 Be yourself. Everyone else is taken. -Oscar Wilde 215 1 Be yourself. Everyone else is taken. -Oscar Wilde
216 2 Don't cry because it's over, smile because it happened. -Dr. Seuss 216 2 Don't cry because it's over, smile because it happened. -Dr. Seuss
217 3 You only live once, but if you do it right, once is enough. -Mae West 217 3 You only live once, but if you do it right, once is enough. -Mae West
218 ... 218 ...
219 {% endprettify %} 219 </pre>
220 220
221 The program displays the contents of the source code file and 221 The program displays the contents of the source code file and
222 preceeds each line with a line number. 222 preceeds each line with a line number.
223 </li> 223 </li>
224 224
225 </ol> 225 </ol>
226 226
227 The following diagram shows how the `dcat` command line used above 227 The following diagram shows how the `dcat` command line used above
228 is parsed into the `ArgResults` object. 228 is parsed into the `ArgResults` object.
229 229
230 ![ArgsParser parses command-line arguments](images/commandlineargs.png) 230 ![ArgsParser parses command-line arguments](images/commandlineargs.png)
231 231
232 You can access flags and options by name, 232 You can access flags and options by name,
233 treating the ArgResults object like a Map. 233 treating the ArgResults object like a Map.
234 You can access other values with properties such as `rest`. 234 You can access other values with properties such as `rest`.
235 235
236 Here's the code from `dcat` that deals with command-line arguments: 236 Here's the code from `dcat` that deals with command-line arguments:
237 237
238 <pre class="prettyprint lang-dart"> 238 <pre class="prettyprint lang-dart">
239
240 ... 239 ...
241 <a href="#" class="dart-popover" data-toggle="popover" title="Parsed arguments" data-html="true" data-trigger="hover focus" data-content="This object contains p arsed options and flags.">ArgResults argResults;</a> 240 <a href="#" class="dart-popover" data-toggle="popover" title="Parsed arguments" data-html="true" data-trigger="hover focus" data-content="This object contains p arsed options and flags.">ArgResults argResults;</a>
242 241
243 void main(<a href="#" class="dart-popover" data-toggle="popover" title="Command- line arguments" data-html="true" data-trigger="hover focus" data-content="The sy stem passes command-line arguments into the program in a list of strings.">List& lt;String&gt; arguments</a>) { 242 void main(<a href="#" class="dart-popover" data-toggle="popover" title="Command- line arguments" data-html="true" data-trigger="hover focus" data-content="The sy stem passes command-line arguments into the program in a list of strings.">List& lt;String&gt; arguments</a>) {
244 final parser = new ArgParser() 243 final parser = new ArgParser()
245 <a href="#" class="dart-popover" data-toggle="popover" title="Define a val id flag" data-html="true" data-trigger="hover focus" data-content="Add a flag de finition to the command-line argument parser. This code defines the flag -n, whi ch when used displays line numbers.">..addFlag(LINE_NUMBER, negatable: false, ab br: 'n')</a>; 244 <a href="#" class="dart-popover" data-toggle="popover" title="Define a val id flag" data-html="true" data-trigger="hover focus" data-content="Add a flag de finition to the command-line argument parser. This code defines the flag -n, whi ch when used displays line numbers.">..addFlag(LINE_NUMBER, negatable: false, ab br: 'n')</a>;
246 245
247 argResults = parser.<a href="#" class="dart-popover" data-toggle="popover" tit le="Parse the arguments" data-html="true" data-trigger="hover focus" data-conten t="Parse the arguments that were passed into the main() function. The parser sto ps parsing if it finds an undefined option or flag.">parse(arguments)</a>; 246 argResults = parser.<a href="#" class="dart-popover" data-toggle="popover" tit le="Parse the arguments" data-html="true" data-trigger="hover focus" data-conten t="Parse the arguments that were passed into the main() function. The parser sto ps parsing if it finds an undefined option or flag.">parse(arguments)</a>;
248 List&lt;String&gt; paths = <a href="#" class="dart-popover" data-toggle="popov er" title="Remaining arguments" data-html="true" data-trigger="hover focus" data -content="To get the arguments that remain after parsing all of the valid option s and flags, use the rest property.">argResults.rest</a>; 247 List&lt;String&gt; paths = <a href="#" class="dart-popover" data-toggle="popov er" title="Remaining arguments" data-html="true" data-trigger="hover focus" data -content="To get the arguments that remain after parsing all of the valid option s and flags, use the rest property.">argResults.rest</a>;
249 248
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 [Write HTTP Clients & Servers](/docs/tutorials/httpserver/). 634 [Write HTTP Clients & Servers](/docs/tutorials/httpserver/).
636 635
637 * The [Get Input from a Form](/docs/tutorials/forms/) tutorial 636 * The [Get Input from a Form](/docs/tutorials/forms/) tutorial
638 features a client-server. 637 features a client-server.
639 The code for the server, which uses CORS headers and handles 638 The code for the server, which uses CORS headers and handles
640 POST requests, is explained in detail. 639 POST requests, is explained in detail.
641 640
642 {% endcapture %} 641 {% endcapture %}
643 642
644 {% include tutorial.html %} 643 {% include tutorial.html %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698