This file is indexed.

/usr/share/doc/python-cliff-doc/html/user/demoapp.html is in python-cliff-doc 2.11.0-0ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>

    <title>OpenStack Docs: Exploring the Demo App</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link href="../_static/css/bootstrap.min.css" rel="stylesheet">

<!-- Pygments CSS -->
<link href="../_static/css/native.css" rel="stylesheet">

<!-- Fonts -->
<link href="../_static/css/font-awesome.min.css" rel="stylesheet">

<!-- Custom CSS -->
<link href="../_static/css/combined.css" rel="stylesheet">
  

  </head>
  <body>

<!-- SOURCE_FILE: https://git.openstack.org/cgit/openstack/cliff/tree/doc/source/user/demoapp.rst -->

 <script type="text/javascript">
    (function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
                (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
        e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
    })(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');

    _st('install','aDn5L_vgZ2yzRcE893kK','2.0.0');
</script>
<nav class="navbar navbar-default" role="navigation">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button class="navbar-toggle" data-target="#bs-example-navbar-collapse-1" data-toggle="collapse" type="button">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <div class="brand-wrapper">
        <a class="navbar-brand" href="index.html"></a>
      </div>
    </div>
  </div>
  <!-- /.container -->
</nav>
    <div class="container docs-book-wrapper">
      <div class="row">
        <div class="col-lg-9 col-md-8 col-sm-8 col-lg-push-3 col-md-push-4 col-sm-push-4">
<div class="row">
  <div class="col-lg-8">
      <h2>Exploring the Demo App</h2>
    
  </div>
  <div class="docs-actions">
    
    <a href="introduction.html"><i class="fa fa-angle-double-left" data-toggle="tooltip" data-placement="top" title="Previous: Introduction"></i></a>
    
    
    <a href="list_commands.html"><i class="fa fa-angle-double-right" data-toggle="tooltip" data-placement="top" title="Next: List Commands"></i></a>
    
    <a id="logABugLink1" href="" target="_blank" title="Found an error? Report a bug against this page"><i class="fa fa-bug" data-toggle="tooltip" data-placement="top" title="Report a Bug"></i></a>
    
  </div>
</div>
          <div class="row docs-byline">
            <div class="docs-updated">updated: 2018-02-28 22:04</div>
          </div>
          <div class="row">
            <div class="col-lg-12">
              <div class="docs-body">

  <div class="section" id="exploring-the-demo-app">
<h1>Exploring the Demo App<a class="headerlink" href="#exploring-the-demo-app" title="Permalink to this headline"></a></h1>
<p>The cliff source package includes a <code class="docutils literal"><span class="pre">demoapp</span></code> directory containing an example
main program with several command plugins.</p>
<div class="section" id="setup">
<h2>Setup<a class="headerlink" href="#setup" title="Permalink to this headline"></a></h2>
<p>To install and experiment with the demo app you should create a virtual
environment and activate it. This will make it easy to remove the app later,
since it doesn’t do anything useful and you aren’t likely to want to hang onto
it after you understand how it works:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ pip install virtualenv
$ virtualenv .venv
$ . .venv/bin/activate
(.venv)$
</pre></div>
</div>
<p>Next, install cliff in the same environment:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ python setup.py install
</pre></div>
</div>
<p>Finally, install the demo application into the virtual environment:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ cd demoapp
(.venv)$ python setup.py install
</pre></div>
</div>
</div>
<div class="section" id="usage">
<h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline"></a></h2>
<p>Both cliff and the demo installed, you can now run the command <code class="docutils literal"><span class="pre">cliffdemo</span></code>.</p>
<p>For basic command usage instructions and a list of the commands available from
the plugins, run:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ cliffdemo -h
</pre></div>
</div>
<p>or:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ cliffdemo --help
</pre></div>
</div>
<p>Run the <code class="docutils literal"><span class="pre">simple</span></code> command by passing its name as argument to <code class="docutils literal"><span class="pre">cliffdemo</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ cliffdemo simple
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">simple</span></code> command prints this output to the console:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>sending greeting
hi!
</pre></div>
</div>
<p>To see help for an individual command, use the <code class="docutils literal"><span class="pre">help</span></code> command:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ cliffdemo help files
</pre></div>
</div>
<p>or the <code class="docutils literal"><span class="pre">--help</span></code> option:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ cliffdemo files --help
</pre></div>
</div>
<p>For more information, refer to the autogenerated documentation <a class="reference internal" href="#demoapp-sphinx"><span class="std std-ref">below</span></a>.</p>
</div>
<div class="section" id="the-source">
<h2>The Source<a class="headerlink" href="#the-source" title="Permalink to this headline"></a></h2>
<p>The <code class="docutils literal"><span class="pre">cliffdemo</span></code> application is defined in a <code class="docutils literal"><span class="pre">cliffdemo</span></code> package containing
several modules.</p>
<div class="section" id="main-py">
<h3>main.py<a class="headerlink" href="#main-py" title="Permalink to this headline"></a></h3>
<p>The main application is defined in <code class="docutils literal"><span class="pre">main.py</span></code>:</p>
<div class="highlight-default"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 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</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">sys</span>

<span class="kn">from</span> <span class="nn">cliff.app</span> <span class="k">import</span> <span class="n">App</span>
<span class="kn">from</span> <span class="nn">cliff.commandmanager</span> <span class="k">import</span> <span class="n">CommandManager</span>


<span class="k">class</span> <span class="nc">DemoApp</span><span class="p">(</span><span class="n">App</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">DemoApp</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">description</span><span class="o">=</span><span class="s1">&#39;cliff demo app&#39;</span><span class="p">,</span>
            <span class="n">version</span><span class="o">=</span><span class="s1">&#39;0.1&#39;</span><span class="p">,</span>
            <span class="n">command_manager</span><span class="o">=</span><span class="n">CommandManager</span><span class="p">(</span><span class="s1">&#39;cliff.demo&#39;</span><span class="p">),</span>
            <span class="n">deferred_help</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
            <span class="p">)</span>

    <span class="k">def</span> <span class="nf">initialize_app</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">argv</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">LOG</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;initialize_app&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">prepare_to_run_command</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cmd</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">LOG</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;prepare_to_run_command </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">cmd</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">clean_up</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cmd</span><span class="p">,</span> <span class="n">result</span><span class="p">,</span> <span class="n">err</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">LOG</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;clean_up </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">cmd</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">err</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">LOG</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;got an error: </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">main</span><span class="p">(</span><span class="n">argv</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">:]):</span>
    <span class="n">myapp</span> <span class="o">=</span> <span class="n">DemoApp</span><span class="p">()</span>
    <span class="k">return</span> <span class="n">myapp</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">argv</span><span class="p">)</span>


<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">main</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">:]))</span>
</pre></div>
</td></tr></table></div>
<p>The <code class="xref py py-class docutils literal"><span class="pre">DemoApp</span></code> class inherits from <code class="xref py py-class docutils literal"><span class="pre">App</span></code> and overrides
<code class="xref py py-func docutils literal"><span class="pre">__init__()</span></code> to set the program description and version number. It also
passes a <code class="xref py py-class docutils literal"><span class="pre">CommandManager</span></code> instance configured to look for plugins in the
<code class="docutils literal"><span class="pre">cliff.demo</span></code> namespace.</p>
<p>The <code class="xref py py-func docutils literal"><span class="pre">initialize_app()</span></code> method of <code class="xref py py-class docutils literal"><span class="pre">DemoApp</span></code> will be invoked after the
main program arguments are parsed, but before any command processing is
performed and before the application enters interactive mode. This hook is
intended for opening connections to remote web services, databases, etc. using
arguments passed to the main application.</p>
<p>The <code class="xref py py-func docutils literal"><span class="pre">prepare_to_run_command()</span></code> method of <code class="xref py py-class docutils literal"><span class="pre">DemoApp</span></code> will be invoked
after a command is identified, but before the command is given its arguments
and run. This hook is intended for pre-command validation or setup that must be
repeated and cannot be handled by <code class="xref py py-func docutils literal"><span class="pre">initialize_app()</span></code>.</p>
<p>The <code class="xref py py-func docutils literal"><span class="pre">clean_up()</span></code> method of <code class="xref py py-class docutils literal"><span class="pre">DemoApp</span></code> is invoked after a command
runs. If the command raised an exception, the exception object is passed to
<code class="xref py py-func docutils literal"><span class="pre">clean_up()</span></code>. Otherwise the <code class="docutils literal"><span class="pre">err</span></code> argument is <code class="docutils literal"><span class="pre">None</span></code>.</p>
<p>The <code class="xref py py-func docutils literal"><span class="pre">main()</span></code> function defined in <code class="docutils literal"><span class="pre">main.py</span></code> is registered as a console
script entry point so that <code class="xref py py-class docutils literal"><span class="pre">DemoApp</span></code> can be run from the command line
(see the discussion of <code class="docutils literal"><span class="pre">setup.py</span></code> below).</p>
</div>
<div class="section" id="simple-py">
<h3>simple.py<a class="headerlink" href="#simple-py" title="Permalink to this headline"></a></h3>
<p>Two commands are defined in <code class="docutils literal"><span class="pre">simple.py</span></code>:</p>
<div class="highlight-default"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">logging</span>

<span class="kn">from</span> <span class="nn">cliff.command</span> <span class="k">import</span> <span class="n">Command</span>


<span class="k">class</span> <span class="nc">Simple</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
    <span class="s2">&quot;A simple command that prints a message.&quot;</span>

    <span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">take_action</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parsed_args</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;sending greeting&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;debugging&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">app</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;hi!</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>


<span class="k">class</span> <span class="nc">Error</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
    <span class="s2">&quot;Always raises an error&quot;</span>

    <span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">take_action</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parsed_args</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;causing error&#39;</span><span class="p">)</span>
        <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;this is the expected exception&#39;</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
<p><code class="xref py py-class docutils literal"><span class="pre">Simple</span></code> demonstrates using logging to emit messages on the console at
different verbose levels:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ cliffdemo simple
sending greeting
hi!

(.venv)$ cliffdemo -v simple
prepare_to_run_command Simple
sending greeting
debugging
hi!
clean_up Simple

(.venv)$ cliffdemo -q simple
hi!
</pre></div>
</div>
<p><code class="xref py py-class docutils literal"><span class="pre">Error</span></code> always raises a <code class="xref py py-class docutils literal"><span class="pre">RuntimeError</span></code> exception when it is
invoked, and can be used to experiment with the error handling features of
cliff:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ cliffdemo error
causing error
ERROR: this is the expected exception

(.venv)$ cliffdemo -v error
prepare_to_run_command Error
causing error
ERROR: this is the expected exception
clean_up Error
got an error: this is the expected exception

(.venv)$ cliffdemo --debug error
causing error
this is the expected exception
Traceback (most recent call last):
  File &quot;.../cliff/app.py&quot;, line 218, in run_subcommand
    result = cmd.run(parsed_args)
  File &quot;.../cliff/command.py&quot;, line 43, in run
    self.take_action(parsed_args)
  File &quot;.../demoapp/cliffdemo/simple.py&quot;, line 24, in take_action
    raise RuntimeError(&#39;this is the expected exception&#39;)
RuntimeError: this is the expected exception
Traceback (most recent call last):
  File &quot;/Users/dhellmann/Envs/cliff/bin/cliffdemo&quot;, line 9, in &lt;module&gt;
    load_entry_point(&#39;cliffdemo==0.1&#39;, &#39;console_scripts&#39;, &#39;cliffdemo&#39;)()
  File &quot;.../demoapp/cliffdemo/main.py&quot;, line 33, in main
    return myapp.run(argv)
  File &quot;.../cliff/app.py&quot;, line 160, in run
    result = self.run_subcommand(remainder)
  File &quot;.../cliff/app.py&quot;, line 218, in run_subcommand
    result = cmd.run(parsed_args)
  File &quot;.../cliff/command.py&quot;, line 43, in run
    self.take_action(parsed_args)
  File &quot;.../demoapp/cliffdemo/simple.py&quot;, line 24, in take_action
    raise RuntimeError(&#39;this is the expected exception&#39;)
RuntimeError: this is the expected exception
</pre></div>
</div>
</div>
<div class="section" id="list-py">
<span id="demoapp-list"></span><h3>list.py<a class="headerlink" href="#list-py" title="Permalink to this headline"></a></h3>
<p><code class="docutils literal"><span class="pre">list.py</span></code> includes a single command derived from <a class="reference internal" href="../reference/index.html#cliff.lister.Lister" title="cliff.lister.Lister"><code class="xref py py-class docutils literal"><span class="pre">cliff.lister.Lister</span></code></a>
which prints a list of the files in the current directory.</p>
<div class="highlight-default"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">os</span>

<span class="kn">from</span> <span class="nn">cliff.lister</span> <span class="k">import</span> <span class="n">Lister</span>


<span class="k">class</span> <span class="nc">Files</span><span class="p">(</span><span class="n">Lister</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Show a list of files in the current directory.</span>

<span class="sd">    The file name and size are printed by default.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">take_action</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parsed_args</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">((</span><span class="s1">&#39;Name&#39;</span><span class="p">,</span> <span class="s1">&#39;Size&#39;</span><span class="p">),</span>
                <span class="p">((</span><span class="n">n</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">st_size</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">))</span>
                <span class="p">)</span>
</pre></div>
</td></tr></table></div>
<p><code class="xref py py-class docutils literal"><span class="pre">Files</span></code> prepares the data, and <code class="xref py py-class docutils literal"><span class="pre">Lister</span></code> manages the output
formatter and printing the data to the console:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ cliffdemo files
+---------------+------+
|      Name     | Size |
+---------------+------+
| build         |  136 |
| cliffdemo.log | 2546 |
| Makefile      | 5569 |
| source        |  408 |
+---------------+------+

(.venv)$ cliffdemo files -f csv
&quot;Name&quot;,&quot;Size&quot;
&quot;build&quot;,136
&quot;cliffdemo.log&quot;,2690
&quot;Makefile&quot;,5569
&quot;source&quot;,408
</pre></div>
</div>
</div>
<div class="section" id="show-py">
<span id="demoapp-show"></span><h3>show.py<a class="headerlink" href="#show-py" title="Permalink to this headline"></a></h3>
<p><code class="docutils literal"><span class="pre">show.py</span></code> includes a single command derived from <a class="reference internal" href="../reference/index.html#cliff.show.ShowOne" title="cliff.show.ShowOne"><code class="xref py py-class docutils literal"><span class="pre">cliff.show.ShowOne</span></code></a>
which prints the properties of the named file.</p>
<div class="highlight-default"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 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</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">os</span>

<span class="kn">from</span> <span class="nn">cliff.show</span> <span class="k">import</span> <span class="n">ShowOne</span>


<span class="k">class</span> <span class="nc">File</span><span class="p">(</span><span class="n">ShowOne</span><span class="p">):</span>
    <span class="s2">&quot;Show details about a file&quot;</span>

    <span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">get_parser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">prog_name</span><span class="p">):</span>
        <span class="n">parser</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">File</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">get_parser</span><span class="p">(</span><span class="n">prog_name</span><span class="p">)</span>
        <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;filename&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="s1">&#39;?&#39;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s1">&#39;.&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">parser</span>

    <span class="k">def</span> <span class="nf">take_action</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parsed_args</span><span class="p">):</span>
        <span class="n">stat_data</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="n">parsed_args</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
        <span class="n">columns</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;Name&#39;</span><span class="p">,</span>
                   <span class="s1">&#39;Size&#39;</span><span class="p">,</span>
                   <span class="s1">&#39;UID&#39;</span><span class="p">,</span>
                   <span class="s1">&#39;GID&#39;</span><span class="p">,</span>
                   <span class="s1">&#39;Modified Time&#39;</span><span class="p">,</span>
                   <span class="p">)</span>
        <span class="n">data</span> <span class="o">=</span> <span class="p">(</span><span class="n">parsed_args</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span>
                <span class="n">stat_data</span><span class="o">.</span><span class="n">st_size</span><span class="p">,</span>
                <span class="n">stat_data</span><span class="o">.</span><span class="n">st_uid</span><span class="p">,</span>
                <span class="n">stat_data</span><span class="o">.</span><span class="n">st_gid</span><span class="p">,</span>
                <span class="n">stat_data</span><span class="o">.</span><span class="n">st_mtime</span><span class="p">,</span>
                <span class="p">)</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">columns</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
<p><code class="xref py py-class docutils literal"><span class="pre">File</span></code> prepares the data, and <code class="xref py py-class docutils literal"><span class="pre">ShowOne</span></code> manages the output
formatter and printing the data to the console:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ cliffdemo file setup.py
+---------------+--------------+
|     Field     |    Value     |
+---------------+--------------+
| Name          | setup.py     |
| Size          | 5825         |
| UID           | 502          |
| GID           | 20           |
| Modified Time | 1335569964.0 |
+---------------+--------------+
</pre></div>
</div>
</div>
<div class="section" id="setup-py">
<h3>setup.py<a class="headerlink" href="#setup-py" title="Permalink to this headline"></a></h3>
<p>The demo application is packaged using setuptools.</p>
<div class="highlight-default"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 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</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>

<span class="n">PROJECT</span> <span class="o">=</span> <span class="s1">&#39;cliffdemo&#39;</span>

<span class="c1"># Change docs/sphinx/conf.py too!</span>
<span class="n">VERSION</span> <span class="o">=</span> <span class="s1">&#39;0.1&#39;</span>

<span class="kn">from</span> <span class="nn">setuptools</span> <span class="k">import</span> <span class="n">setup</span><span class="p">,</span> <span class="n">find_packages</span>

<span class="k">try</span><span class="p">:</span>
    <span class="n">long_description</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s1">&#39;README.rst&#39;</span><span class="p">,</span> <span class="s1">&#39;rt&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
    <span class="n">long_description</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>

<span class="n">setup</span><span class="p">(</span>
    <span class="n">name</span><span class="o">=</span><span class="n">PROJECT</span><span class="p">,</span>
    <span class="n">version</span><span class="o">=</span><span class="n">VERSION</span><span class="p">,</span>

    <span class="n">description</span><span class="o">=</span><span class="s1">&#39;Demo app for cliff&#39;</span><span class="p">,</span>
    <span class="n">long_description</span><span class="o">=</span><span class="n">long_description</span><span class="p">,</span>

    <span class="n">author</span><span class="o">=</span><span class="s1">&#39;Doug Hellmann&#39;</span><span class="p">,</span>
    <span class="n">author_email</span><span class="o">=</span><span class="s1">&#39;doug.hellmann@gmail.com&#39;</span><span class="p">,</span>

    <span class="n">url</span><span class="o">=</span><span class="s1">&#39;https://github.com/openstack/cliff&#39;</span><span class="p">,</span>
    <span class="n">download_url</span><span class="o">=</span><span class="s1">&#39;https://github.com/openstack/cliff/tarball/master&#39;</span><span class="p">,</span>

    <span class="n">classifiers</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;Development Status :: 3 - Alpha&#39;</span><span class="p">,</span>
                 <span class="s1">&#39;License :: OSI Approved :: Apache Software License&#39;</span><span class="p">,</span>
                 <span class="s1">&#39;Programming Language :: Python&#39;</span><span class="p">,</span>
                 <span class="s1">&#39;Programming Language :: Python :: 2&#39;</span><span class="p">,</span>
                 <span class="s1">&#39;Programming Language :: Python :: 2.7&#39;</span><span class="p">,</span>
                 <span class="s1">&#39;Programming Language :: Python :: 3&#39;</span><span class="p">,</span>
                 <span class="s1">&#39;Programming Language :: Python :: 3.2&#39;</span><span class="p">,</span>
                 <span class="s1">&#39;Intended Audience :: Developers&#39;</span><span class="p">,</span>
                 <span class="s1">&#39;Environment :: Console&#39;</span><span class="p">,</span>
                 <span class="p">],</span>

    <span class="n">platforms</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;Any&#39;</span><span class="p">],</span>

    <span class="n">scripts</span><span class="o">=</span><span class="p">[],</span>

    <span class="n">provides</span><span class="o">=</span><span class="p">[],</span>
    <span class="n">install_requires</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;cliff&#39;</span><span class="p">],</span>

    <span class="n">namespace_packages</span><span class="o">=</span><span class="p">[],</span>
    <span class="n">packages</span><span class="o">=</span><span class="n">find_packages</span><span class="p">(),</span>
    <span class="n">include_package_data</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>

    <span class="n">entry_points</span><span class="o">=</span><span class="p">{</span>
        <span class="s1">&#39;console_scripts&#39;</span><span class="p">:</span> <span class="p">[</span>
            <span class="s1">&#39;cliffdemo = cliffdemo.main:main&#39;</span>
        <span class="p">],</span>
        <span class="s1">&#39;cliff.demo&#39;</span><span class="p">:</span> <span class="p">[</span>
            <span class="s1">&#39;simple = cliffdemo.simple:Simple&#39;</span><span class="p">,</span>
            <span class="s1">&#39;two_part = cliffdemo.simple:Simple&#39;</span><span class="p">,</span>
            <span class="s1">&#39;error = cliffdemo.simple:Error&#39;</span><span class="p">,</span>
            <span class="s1">&#39;list files = cliffdemo.list:Files&#39;</span><span class="p">,</span>
            <span class="s1">&#39;files = cliffdemo.list:Files&#39;</span><span class="p">,</span>
            <span class="s1">&#39;file = cliffdemo.show:File&#39;</span><span class="p">,</span>
            <span class="s1">&#39;show file = cliffdemo.show:File&#39;</span><span class="p">,</span>
            <span class="s1">&#39;unicode = cliffdemo.encoding:Encoding&#39;</span><span class="p">,</span>
            <span class="s1">&#39;hooked = cliffdemo.hook:Hooked&#39;</span><span class="p">,</span>
        <span class="p">],</span>
        <span class="s1">&#39;cliff.demo.hooked&#39;</span><span class="p">:</span> <span class="p">[</span>
            <span class="s1">&#39;sample-hook = cliffdemo.hook:Hook&#39;</span><span class="p">,</span>
        <span class="p">],</span>
    <span class="p">},</span>

    <span class="n">zip_safe</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</td></tr></table></div>
<p>The important parts of the packaging instructions are the <code class="docutils literal"><span class="pre">entry_points</span></code>
settings. All of the commands are registered in the <code class="docutils literal"><span class="pre">cliff.demo</span></code> namespace.
Each main program should define its own command namespace so that it only loads
the command plugins that it should be managing.</p>
</div>
</div>
<div class="section" id="command-extension-hooks">
<h2>Command Extension Hooks<a class="headerlink" href="#command-extension-hooks" title="Permalink to this headline"></a></h2>
<p>Individual subcommands of an application can be extended via hooks registered
as separate plugins. In the demo application, the <code class="docutils literal"><span class="pre">hooked</span></code> command has a
single extension registered.</p>
<p>The namespace for hooks is a combination of the application namespace and the
command name. In this case, the application namespace is <code class="docutils literal"><span class="pre">cliff.demo</span></code> and the
command is <code class="docutils literal"><span class="pre">hooked</span></code>, so the extension namespace is <code class="docutils literal"><span class="pre">cliff.demo.hooked</span></code>. If
the subcommand name includes spaces, they are replaced with underscores
(“<code class="docutils literal"><span class="pre">_</span></code>”) to build the namespace.</p>
<div class="highlight-default"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 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</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># All Rights Reserved.</span>
<span class="c1">#</span>
<span class="c1">#    Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); you may</span>
<span class="c1">#    not use this file except in compliance with the License. You may obtain</span>
<span class="c1">#    a copy of the License at</span>
<span class="c1">#</span>
<span class="c1">#         http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1">#    Unless required by applicable law or agreed to in writing, software</span>
<span class="c1">#    distributed under the License is distributed on an &quot;AS IS&quot; BASIS, WITHOUT</span>
<span class="c1">#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the</span>
<span class="c1">#    License for the specific language governing permissions and limitations</span>
<span class="c1">#    under the License.</span>

<span class="kn">import</span> <span class="nn">logging</span>

<span class="kn">from</span> <span class="nn">cliff.command</span> <span class="k">import</span> <span class="n">Command</span>
<span class="kn">from</span> <span class="nn">cliff.hooks</span> <span class="k">import</span> <span class="n">CommandHook</span>


<span class="k">class</span> <span class="nc">Hooked</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
    <span class="s2">&quot;A command to demonstrate how the hooks work&quot;</span>

    <span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">take_action</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parsed_args</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">app</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;this command has an extension</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>


<span class="k">class</span> <span class="nc">Hook</span><span class="p">(</span><span class="n">CommandHook</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Hook sample for the &#39;hooked&#39; command.</span>

<span class="sd">    This would normally be provided by a separate package from the</span>
<span class="sd">    main application, but is included in the demo app for simplicity.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">get_parser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parser</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;sample hook get_parser()&#39;</span><span class="p">)</span>
        <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--added-by-hook&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">parser</span>

    <span class="k">def</span> <span class="nf">get_epilog</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;extension epilog text&#39;</span>

    <span class="k">def</span> <span class="nf">before</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parsed_args</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cmd</span><span class="o">.</span><span class="n">app</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;before</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">after</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parsed_args</span><span class="p">,</span> <span class="n">return_code</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cmd</span><span class="o">.</span><span class="n">app</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;after</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
<p>Although the <code class="docutils literal"><span class="pre">hooked</span></code> command does not add any arguments to the parser it
creates, the help output shows that the extension adds a single
<code class="docutils literal"><span class="pre">--added-by-hook</span></code> option.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>(.venv)$ cliffdemo hooked -h
sample hook get_parser()
usage: cliffdemo hooked [-h] [--added-by-hook ADDED_BY_HOOK]

A command to demonstrate how the hooks work

optional arguments:
  -h, --help            show this help message and exit
  --added-by-hook ADDED_BY_HOOK

extension epilog text

(.venv)$ cliffdemo hooked
sample hook get_parser()
before
this command has an extension
after
</pre></div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="../reference/index.html#cliff.hooks.CommandHook" title="cliff.hooks.CommandHook"><code class="xref py py-class docutils literal"><span class="pre">cliff.hooks.CommandHook</span></code></a> – The API for command hooks.</p>
</div>
</div>
<div class="section" id="autogenerated-documentation">
<span id="demoapp-sphinx"></span><h2>Autogenerated Documentation<a class="headerlink" href="#autogenerated-documentation" title="Permalink to this headline"></a></h2>
<p>The following documentation is generated using the following directive, which
is provided by <a class="reference internal" href="sphinxext.html"><span class="doc">the cliff Sphinx extension</span></a>.</p>
<div class="highlight-rest"><div class="highlight"><pre><span></span><span class="p">..</span> <span class="ow">autoprogram-cliff</span><span class="p">::</span> cliffdemo.main.DemoApp
   <span class="nc">:application:</span> <span class="nf">cliffdemo</span>

<span class="p">..</span> <span class="ow">autoprogram-cliff</span><span class="p">::</span> cliff.demo
   <span class="nc">:application:</span> <span class="nf">cliffdemo</span>
</pre></div>
</div>
<div class="section" id="output">
<h3>Output<a class="headerlink" href="#output" title="Permalink to this headline"></a></h3>
<div class="section" id="global-options">
<h4>Global Options<a class="headerlink" href="#global-options" title="Permalink to this headline"></a></h4>
<p>cliff demo app</p>
<div class="highlight-shell"><div class="highlight"><pre><span></span>cliffdemo <span class="o">[</span>--version<span class="o">]</span> <span class="o">[</span>-v <span class="p">|</span> -q<span class="o">]</span> <span class="o">[</span>--log-file LOG_FILE<span class="o">]</span> <span class="o">[</span>--debug<span class="o">]</span>
</pre></div>
</div>
<dl class="option">
<dt id="cmdoption-cliffdemo-version">
<code class="descname">--version</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-version" title="Permalink to this definition"></a></dt>
<dd><p>show program’s version number and exit</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-v">
<code class="descname">-v</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--verbose</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-v" title="Permalink to this definition"></a></dt>
<dd><p>Increase verbosity of output. Can be repeated.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-q">
<code class="descname">-q</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--quiet</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-q" title="Permalink to this definition"></a></dt>
<dd><p>Suppress output except warnings and errors.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-log-file">
<code class="descname">--log-file</code><code class="descclassname"> &lt;LOG_FILE&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-log-file" title="Permalink to this definition"></a></dt>
<dd><p>Specify a file to log output. Disabled by default.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-debug">
<code class="descname">--debug</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-debug" title="Permalink to this definition"></a></dt>
<dd><p>Show tracebacks on errors.</p>
</dd></dl>

</div>
<div class="section" id="command-options">
<h4>Command Options<a class="headerlink" href="#command-options" title="Permalink to this headline"></a></h4>
<div class="section" id="error">
<h5>error<a class="headerlink" href="#error" title="Permalink to this headline"></a></h5>
<p>Always raises an error</p>
<div class="highlight-shell"><div class="highlight"><pre><span></span>cliffdemo error
</pre></div>
</div>
</div>
<div class="section" id="file">
<h5>file<a class="headerlink" href="#file" title="Permalink to this headline"></a></h5>
<p>Show details about a file</p>
<div class="highlight-shell"><div class="highlight"><pre><span></span>cliffdemo file
    <span class="o">[</span>-f <span class="o">{</span>json,shell,table,value,yaml<span class="o">}]</span>
    <span class="o">[</span>-c COLUMN<span class="o">]</span>
    <span class="o">[</span>--max-width &lt;integer&gt;<span class="o">]</span>
    <span class="o">[</span>--fit-width<span class="o">]</span>
    <span class="o">[</span>--print-empty<span class="o">]</span>
    <span class="o">[</span>--noindent<span class="o">]</span>
    <span class="o">[</span>--prefix PREFIX<span class="o">]</span>
    <span class="o">[</span>filename<span class="o">]</span>
</pre></div>
</div>
<dl class="option">
<dt id="cmdoption-cliffdemo-file-f">
<code class="descname">-f</code><code class="descclassname"> &lt;FORMATTER&gt;</code><code class="descclassname">, </code><code class="descname">--format</code><code class="descclassname"> &lt;FORMATTER&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-file-f" title="Permalink to this definition"></a></dt>
<dd><p>the output format, defaults to table</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-file-c">
<code class="descname">-c</code><code class="descclassname"> COLUMN</code><code class="descclassname">, </code><code class="descname">--column</code><code class="descclassname"> COLUMN</code><a class="headerlink" href="#cmdoption-cliffdemo-file-c" title="Permalink to this definition"></a></dt>
<dd><p>specify the column(s) to include, can be repeated</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-file-max-width">
<code class="descname">--max-width</code><code class="descclassname"> &lt;integer&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-file-max-width" title="Permalink to this definition"></a></dt>
<dd><p>Maximum display width, &lt;1 to disable. You can also use the CLIFF_MAX_TERM_WIDTH environment variable, but the parameter takes precedence.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-file-fit-width">
<code class="descname">--fit-width</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-file-fit-width" title="Permalink to this definition"></a></dt>
<dd><p>Fit the table to the display width. Implied if –max-width greater than 0. Set the environment variable CLIFF_FIT_WIDTH=1 to always enable</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-file-print-empty">
<code class="descname">--print-empty</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-file-print-empty" title="Permalink to this definition"></a></dt>
<dd><p>Print empty table if there is no data to show.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-file-noindent">
<code class="descname">--noindent</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-file-noindent" title="Permalink to this definition"></a></dt>
<dd><p>whether to disable indenting the JSON</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-file-prefix">
<code class="descname">--prefix</code><code class="descclassname"> &lt;PREFIX&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-file-prefix" title="Permalink to this definition"></a></dt>
<dd><p>add a prefix to all variable names</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-file-arg-filename">
<code class="descname">filename</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-file-arg-filename" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</div>
<div class="section" id="files">
<h5>files<a class="headerlink" href="#files" title="Permalink to this headline"></a></h5>
<p>Show a list of files in the current directory.</p>
<p>The file name and size are printed by default.</p>
<div class="highlight-shell"><div class="highlight"><pre><span></span>cliffdemo files
    <span class="o">[</span>-f <span class="o">{</span>csv,json,table,value,yaml<span class="o">}]</span>
    <span class="o">[</span>-c COLUMN<span class="o">]</span>
    <span class="o">[</span>--max-width &lt;integer&gt;<span class="o">]</span>
    <span class="o">[</span>--fit-width<span class="o">]</span>
    <span class="o">[</span>--print-empty<span class="o">]</span>
    <span class="o">[</span>--noindent<span class="o">]</span>
    <span class="o">[</span>--quote <span class="o">{</span>all,minimal,none,nonnumeric<span class="o">}]</span>
    <span class="o">[</span>--sort-column SORT_COLUMN<span class="o">]</span>
</pre></div>
</div>
<dl class="option">
<dt id="cmdoption-cliffdemo-files-f">
<code class="descname">-f</code><code class="descclassname"> &lt;FORMATTER&gt;</code><code class="descclassname">, </code><code class="descname">--format</code><code class="descclassname"> &lt;FORMATTER&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-files-f" title="Permalink to this definition"></a></dt>
<dd><p>the output format, defaults to table</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-files-c">
<code class="descname">-c</code><code class="descclassname"> COLUMN</code><code class="descclassname">, </code><code class="descname">--column</code><code class="descclassname"> COLUMN</code><a class="headerlink" href="#cmdoption-cliffdemo-files-c" title="Permalink to this definition"></a></dt>
<dd><p>specify the column(s) to include, can be repeated</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-files-max-width">
<code class="descname">--max-width</code><code class="descclassname"> &lt;integer&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-files-max-width" title="Permalink to this definition"></a></dt>
<dd><p>Maximum display width, &lt;1 to disable. You can also use the CLIFF_MAX_TERM_WIDTH environment variable, but the parameter takes precedence.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-files-fit-width">
<code class="descname">--fit-width</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-files-fit-width" title="Permalink to this definition"></a></dt>
<dd><p>Fit the table to the display width. Implied if –max-width greater than 0. Set the environment variable CLIFF_FIT_WIDTH=1 to always enable</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-files-print-empty">
<code class="descname">--print-empty</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-files-print-empty" title="Permalink to this definition"></a></dt>
<dd><p>Print empty table if there is no data to show.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-files-noindent">
<code class="descname">--noindent</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-files-noindent" title="Permalink to this definition"></a></dt>
<dd><p>whether to disable indenting the JSON</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-files-quote">
<code class="descname">--quote</code><code class="descclassname"> &lt;QUOTE_MODE&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-files-quote" title="Permalink to this definition"></a></dt>
<dd><p>when to include quotes, defaults to nonnumeric</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-files-sort-column">
<code class="descname">--sort-column</code><code class="descclassname"> SORT_COLUMN</code><a class="headerlink" href="#cmdoption-cliffdemo-files-sort-column" title="Permalink to this definition"></a></dt>
<dd><p>specify the column(s) to sort the data (columns specified first have a priority, non-existing columns are ignored), can be repeated</p>
</dd></dl>

</div>
<div class="section" id="hooked">
<h5>hooked<a class="headerlink" href="#hooked" title="Permalink to this headline"></a></h5>
<p>A command to demonstrate how the hooks work</p>
<div class="highlight-shell"><div class="highlight"><pre><span></span>cliffdemo hooked
</pre></div>
</div>
</div>
<div class="section" id="list-files">
<h5>list files<a class="headerlink" href="#list-files" title="Permalink to this headline"></a></h5>
<p>Show a list of files in the current directory.</p>
<p>The file name and size are printed by default.</p>
<div class="highlight-shell"><div class="highlight"><pre><span></span>cliffdemo list files
    <span class="o">[</span>-f <span class="o">{</span>csv,json,table,value,yaml<span class="o">}]</span>
    <span class="o">[</span>-c COLUMN<span class="o">]</span>
    <span class="o">[</span>--max-width &lt;integer&gt;<span class="o">]</span>
    <span class="o">[</span>--fit-width<span class="o">]</span>
    <span class="o">[</span>--print-empty<span class="o">]</span>
    <span class="o">[</span>--noindent<span class="o">]</span>
    <span class="o">[</span>--quote <span class="o">{</span>all,minimal,none,nonnumeric<span class="o">}]</span>
    <span class="o">[</span>--sort-column SORT_COLUMN<span class="o">]</span>
</pre></div>
</div>
<dl class="option">
<dt id="cmdoption-cliffdemo-list-files-f">
<code class="descname">-f</code><code class="descclassname"> &lt;FORMATTER&gt;</code><code class="descclassname">, </code><code class="descname">--format</code><code class="descclassname"> &lt;FORMATTER&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-list-files-f" title="Permalink to this definition"></a></dt>
<dd><p>the output format, defaults to table</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-list-files-c">
<code class="descname">-c</code><code class="descclassname"> COLUMN</code><code class="descclassname">, </code><code class="descname">--column</code><code class="descclassname"> COLUMN</code><a class="headerlink" href="#cmdoption-cliffdemo-list-files-c" title="Permalink to this definition"></a></dt>
<dd><p>specify the column(s) to include, can be repeated</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-list-files-max-width">
<code class="descname">--max-width</code><code class="descclassname"> &lt;integer&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-list-files-max-width" title="Permalink to this definition"></a></dt>
<dd><p>Maximum display width, &lt;1 to disable. You can also use the CLIFF_MAX_TERM_WIDTH environment variable, but the parameter takes precedence.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-list-files-fit-width">
<code class="descname">--fit-width</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-list-files-fit-width" title="Permalink to this definition"></a></dt>
<dd><p>Fit the table to the display width. Implied if –max-width greater than 0. Set the environment variable CLIFF_FIT_WIDTH=1 to always enable</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-list-files-print-empty">
<code class="descname">--print-empty</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-list-files-print-empty" title="Permalink to this definition"></a></dt>
<dd><p>Print empty table if there is no data to show.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-list-files-noindent">
<code class="descname">--noindent</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-list-files-noindent" title="Permalink to this definition"></a></dt>
<dd><p>whether to disable indenting the JSON</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-list-files-quote">
<code class="descname">--quote</code><code class="descclassname"> &lt;QUOTE_MODE&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-list-files-quote" title="Permalink to this definition"></a></dt>
<dd><p>when to include quotes, defaults to nonnumeric</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-list-files-sort-column">
<code class="descname">--sort-column</code><code class="descclassname"> SORT_COLUMN</code><a class="headerlink" href="#cmdoption-cliffdemo-list-files-sort-column" title="Permalink to this definition"></a></dt>
<dd><p>specify the column(s) to sort the data (columns specified first have a priority, non-existing columns are ignored), can be repeated</p>
</dd></dl>

</div>
<div class="section" id="show-file">
<h5>show file<a class="headerlink" href="#show-file" title="Permalink to this headline"></a></h5>
<p>Show details about a file</p>
<div class="highlight-shell"><div class="highlight"><pre><span></span>cliffdemo show file
    <span class="o">[</span>-f <span class="o">{</span>json,shell,table,value,yaml<span class="o">}]</span>
    <span class="o">[</span>-c COLUMN<span class="o">]</span>
    <span class="o">[</span>--max-width &lt;integer&gt;<span class="o">]</span>
    <span class="o">[</span>--fit-width<span class="o">]</span>
    <span class="o">[</span>--print-empty<span class="o">]</span>
    <span class="o">[</span>--noindent<span class="o">]</span>
    <span class="o">[</span>--prefix PREFIX<span class="o">]</span>
    <span class="o">[</span>filename<span class="o">]</span>
</pre></div>
</div>
<dl class="option">
<dt id="cmdoption-cliffdemo-show-file-f">
<code class="descname">-f</code><code class="descclassname"> &lt;FORMATTER&gt;</code><code class="descclassname">, </code><code class="descname">--format</code><code class="descclassname"> &lt;FORMATTER&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-show-file-f" title="Permalink to this definition"></a></dt>
<dd><p>the output format, defaults to table</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-show-file-c">
<code class="descname">-c</code><code class="descclassname"> COLUMN</code><code class="descclassname">, </code><code class="descname">--column</code><code class="descclassname"> COLUMN</code><a class="headerlink" href="#cmdoption-cliffdemo-show-file-c" title="Permalink to this definition"></a></dt>
<dd><p>specify the column(s) to include, can be repeated</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-show-file-max-width">
<code class="descname">--max-width</code><code class="descclassname"> &lt;integer&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-show-file-max-width" title="Permalink to this definition"></a></dt>
<dd><p>Maximum display width, &lt;1 to disable. You can also use the CLIFF_MAX_TERM_WIDTH environment variable, but the parameter takes precedence.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-show-file-fit-width">
<code class="descname">--fit-width</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-show-file-fit-width" title="Permalink to this definition"></a></dt>
<dd><p>Fit the table to the display width. Implied if –max-width greater than 0. Set the environment variable CLIFF_FIT_WIDTH=1 to always enable</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-show-file-print-empty">
<code class="descname">--print-empty</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-show-file-print-empty" title="Permalink to this definition"></a></dt>
<dd><p>Print empty table if there is no data to show.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-show-file-noindent">
<code class="descname">--noindent</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-show-file-noindent" title="Permalink to this definition"></a></dt>
<dd><p>whether to disable indenting the JSON</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-show-file-prefix">
<code class="descname">--prefix</code><code class="descclassname"> &lt;PREFIX&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-show-file-prefix" title="Permalink to this definition"></a></dt>
<dd><p>add a prefix to all variable names</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-show-file-arg-filename">
<code class="descname">filename</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-show-file-arg-filename" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</div>
<div class="section" id="simple">
<h5>simple<a class="headerlink" href="#simple" title="Permalink to this headline"></a></h5>
<p>A simple command that prints a message.</p>
<div class="highlight-shell"><div class="highlight"><pre><span></span>cliffdemo simple
</pre></div>
</div>
</div>
<div class="section" id="two-part">
<h5>two part<a class="headerlink" href="#two-part" title="Permalink to this headline"></a></h5>
<p>A simple command that prints a message.</p>
<div class="highlight-shell"><div class="highlight"><pre><span></span>cliffdemo two part
</pre></div>
</div>
</div>
<div class="section" id="unicode">
<h5>unicode<a class="headerlink" href="#unicode" title="Permalink to this headline"></a></h5>
<p>Show some unicode text</p>
<div class="highlight-shell"><div class="highlight"><pre><span></span>cliffdemo unicode
    <span class="o">[</span>-f <span class="o">{</span>csv,json,table,value,yaml<span class="o">}]</span>
    <span class="o">[</span>-c COLUMN<span class="o">]</span>
    <span class="o">[</span>--max-width &lt;integer&gt;<span class="o">]</span>
    <span class="o">[</span>--fit-width<span class="o">]</span>
    <span class="o">[</span>--print-empty<span class="o">]</span>
    <span class="o">[</span>--noindent<span class="o">]</span>
    <span class="o">[</span>--quote <span class="o">{</span>all,minimal,none,nonnumeric<span class="o">}]</span>
    <span class="o">[</span>--sort-column SORT_COLUMN<span class="o">]</span>
</pre></div>
</div>
<dl class="option">
<dt id="cmdoption-cliffdemo-unicode-f">
<code class="descname">-f</code><code class="descclassname"> &lt;FORMATTER&gt;</code><code class="descclassname">, </code><code class="descname">--format</code><code class="descclassname"> &lt;FORMATTER&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-unicode-f" title="Permalink to this definition"></a></dt>
<dd><p>the output format, defaults to table</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-unicode-c">
<code class="descname">-c</code><code class="descclassname"> COLUMN</code><code class="descclassname">, </code><code class="descname">--column</code><code class="descclassname"> COLUMN</code><a class="headerlink" href="#cmdoption-cliffdemo-unicode-c" title="Permalink to this definition"></a></dt>
<dd><p>specify the column(s) to include, can be repeated</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-unicode-max-width">
<code class="descname">--max-width</code><code class="descclassname"> &lt;integer&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-unicode-max-width" title="Permalink to this definition"></a></dt>
<dd><p>Maximum display width, &lt;1 to disable. You can also use the CLIFF_MAX_TERM_WIDTH environment variable, but the parameter takes precedence.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-unicode-fit-width">
<code class="descname">--fit-width</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-unicode-fit-width" title="Permalink to this definition"></a></dt>
<dd><p>Fit the table to the display width. Implied if –max-width greater than 0. Set the environment variable CLIFF_FIT_WIDTH=1 to always enable</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-unicode-print-empty">
<code class="descname">--print-empty</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-unicode-print-empty" title="Permalink to this definition"></a></dt>
<dd><p>Print empty table if there is no data to show.</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-unicode-noindent">
<code class="descname">--noindent</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-cliffdemo-unicode-noindent" title="Permalink to this definition"></a></dt>
<dd><p>whether to disable indenting the JSON</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-unicode-quote">
<code class="descname">--quote</code><code class="descclassname"> &lt;QUOTE_MODE&gt;</code><a class="headerlink" href="#cmdoption-cliffdemo-unicode-quote" title="Permalink to this definition"></a></dt>
<dd><p>when to include quotes, defaults to nonnumeric</p>
</dd></dl>

<dl class="option">
<dt id="cmdoption-cliffdemo-unicode-sort-column">
<code class="descname">--sort-column</code><code class="descclassname"> SORT_COLUMN</code><a class="headerlink" href="#cmdoption-cliffdemo-unicode-sort-column" title="Permalink to this definition"></a></dt>
<dd><p>specify the column(s) to sort the data (columns specified first have a priority, non-existing columns are ignored), can be repeated</p>
</dd></dl>

</div>
</div>
</div>
</div>
</div>


              </div>
            </div>
          </div>
          <div class="docs-actions">
          
            <a href="introduction.html"><i class="fa fa-angle-double-left" data-toggle="tooltip" data-placement="top" title="Previous: Introduction"></i></a>
          
          
            <a href="list_commands.html"><i class="fa fa-angle-double-right" data-toggle="tooltip" data-placement="top" title="Next: List Commands"></i></a>
          
            <a id="logABugLink3" href="" target="_blank" title="Found an error? Report a bug against this page"><i class="fa fa-bug" data-toggle="tooltip" data-placement="top" title="Report a Bug"></i></a>
          
          </div>
          <div class="row docs-byline bottom">
            <div class="docs-updated">updated: 2018-02-28 22:04</div>
          </div>
          <div class="row">
            <div class="col-lg-8 col-md-8 col-sm-8 docs-license">
<a href="https://creativecommons.org/licenses/by/3.0/">
 <img src="../_static/images/docs/license.png" alt="Creative Commons Attribution 3.0 License"/>
</a>
<p>
 Except where otherwise noted, this document is licensed under
 <a href="https://creativecommons.org/licenses/by/3.0/">Creative Commons
 Attribution 3.0 License</a>. See all <a href="http://www.openstack.org/legal">
 OpenStack Legal Documents</a>.
</p>
            </div>
            <div class="col-lg-4 col-md-4 col-sm-4 docs-actions-wrapper">
            <!-- ID buglinkbottom added so that pre-filled doc bugs
                 are sent to Launchpad projects related to the
                 document -->
              <a href="#" id="logABugLink2" class="docs-footer-actions"><i class="fa fa-bug"></i> found an error? report a bug</a>
              <a href="http://ask.openstack.org" class="docs-footer-actions"><i class="fa fa-question-circle"></i> questions?</a>
            </div>
          </div>
        </div>
<div class="col-lg-3 col-md-4 col-sm-4 col-lg-pull-9 col-md-pull-8 col-sm-pull-8 docs-sidebar">
  <div class="btn-group docs-sidebar-releases">
    <button onclick="location.href='/'" class="btn docs-sidebar-home" data-toggle="tooltip" data-placement="top" title="Docs Home"><i class="fa fa-arrow-circle-o-left"></i></button>
<button href="#" type="button" data-toggle="dropdown" class="btn docs-sidebar-release-select">OpenStack Documentation<i class="fa fa-caret-down"></i></button>
    <ul class="dropdown-menu docs-sidebar-dropdown" role="menu" aria-labelledby="dLabel">
      <li role="presentation" class="dropdown-header">Guides</li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#install-guides">Install Guides</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#user-guides">User Guides</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#configuration-guides">Configuration Guides</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#ops-and-admin-guides">Operations and Administration Guides</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#api-guides">API Guides</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#contributor-guides">Contributor Guides</a></li>
      <li role="presentation" class="dropdown-header">Languages</li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/de/">Deutsch (German)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/fr/">Français (French)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/id/">Bahasa Indonesia (Indonesian)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/it/">Italiano (Italian)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/ja/">日本語 (Japanese)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/ko_KR/">한국어 (Korean)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/pt_BR/">Português (Portuguese)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/tr_TR/">Türkçe (Türkiye)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/zh_CN/">简体中文 (Simplified Chinese)</a></li>
    </ul>
  </div>
  <div class="docs-sidebar-toc">
    <div class="docs-sidebar-section" id="table-of-contents">
      <a href="../index.html" class="docs-sidebar-section-title"><h4>cliff 2.11.0</h4></a>
      <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../install/index.html">Installation</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Using cliff</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Exploring the Demo App</a></li>
<li class="toctree-l2"><a class="reference internal" href="list_commands.html">List Commands</a></li>
<li class="toctree-l2"><a class="reference internal" href="show_commands.html">Show Commands</a></li>
<li class="toctree-l2"><a class="reference internal" href="complete.html">Command Completion</a></li>
<li class="toctree-l2"><a class="reference internal" href="interactive_mode.html">Interactive Mode</a></li>
<li class="toctree-l2"><a class="reference internal" href="sphinxext.html">Sphinx Integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="history.html">CHANGES</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../reference/index.html">Cliff Class Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributors/index.html">For Contributors</a></li>
</ul>

    </div>

  <div class="docs-sidebar-toc">
    <div class="docs-sidebar-section" id="local-table-of-contents">
      <h4 class="docs-sidebar-section-title">Page Contents</h4>
      <ul>
<li><a class="reference internal" href="#">Exploring the Demo App</a><ul>
<li><a class="reference internal" href="#setup">Setup</a></li>
<li><a class="reference internal" href="#usage">Usage</a></li>
<li><a class="reference internal" href="#the-source">The Source</a><ul>
<li><a class="reference internal" href="#main-py">main.py</a></li>
<li><a class="reference internal" href="#simple-py">simple.py</a></li>
<li><a class="reference internal" href="#list-py">list.py</a></li>
<li><a class="reference internal" href="#show-py">show.py</a></li>
<li><a class="reference internal" href="#setup-py">setup.py</a></li>
</ul>
</li>
<li><a class="reference internal" href="#command-extension-hooks">Command Extension Hooks</a></li>
<li><a class="reference internal" href="#autogenerated-documentation">Autogenerated Documentation</a><ul>
<li><a class="reference internal" href="#output">Output</a><ul>
<li><a class="reference internal" href="#global-options">Global Options</a></li>
<li><a class="reference internal" href="#command-options">Command Options</a><ul>
<li><a class="reference internal" href="#error">error</a></li>
<li><a class="reference internal" href="#file">file</a></li>
<li><a class="reference internal" href="#files">files</a></li>
<li><a class="reference internal" href="#hooked">hooked</a></li>
<li><a class="reference internal" href="#list-files">list files</a></li>
<li><a class="reference internal" href="#show-file">show file</a></li>
<li><a class="reference internal" href="#simple">simple</a></li>
<li><a class="reference internal" href="#two-part">two part</a></li>
<li><a class="reference internal" href="#unicode">unicode</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

    </div>
  </div>
  </div>
</div>
      </div>
    </div>
<footer>
  <div class="container">
    <div class="row footer-links">
      <div class="col-lg-2 col-sm-2">
        <h3>OpenStack</h3>
        <ul>
          <li><a href="http://openstack.org/projects/">Projects</a></li>
          <li><a href="http://openstack.org/projects/openstack-security/">OpenStack Security</a></li>
          <li><a href="http://openstack.org/projects/openstack-faq/">Common Questions</a></li>
          <li><a href="http://openstack.org/blog/">Blog</a></li>
          <li><a href="http://openstack.org/news/">News</a></li>
        </ul>
      </div>
      <div class="col-lg-2 col-sm-2">
        <h3>Community</h3>
        <ul>
          <li><a href="http://openstack.org/community/">User Groups</a></li>
          <li><a href="http://openstack.org/community/events/">Events</a></li>
          <li><a href="http://openstack.org/community/jobs/">Jobs</a></li>
          <li><a href="http://openstack.org/foundation/companies/">Companies</a></li>
          <li><a href="http://docs.openstack.org/infra/manual/developers.html">Contribute</a></li>
        </ul>
      </div>
      <div class="col-lg-2 col-sm-2">
        <h3>Documentation</h3>
        <ul>
          <li><a href="http://docs.openstack.org">OpenStack Manuals</a></li>
          <li><a href="http://openstack.org/software/start/">Getting Started</a></li>
          <li><a href="http://developer.openstack.org">API Documentation</a></li>
          <li><a href="https://wiki.openstack.org">Wiki</a></li>
        </ul>
      </div>
      <div class="col-lg-2 col-sm-2">
        <h3>Branding & Legal</h3>
        <ul>
          <li><a href="http://openstack.org/brand/">Logos & Guidelines</a></li>
          <li><a href="http://openstack.org/brand/openstack-trademark-policy/">Trademark Policy</a></li>
          <li><a href="http://openstack.org/privacy/">Privacy Policy</a></li>
          <li><a href="https://wiki.openstack.org/wiki/How_To_Contribute#Contributor_License_Agreement">OpenStack CLA</a></li>
        </ul>
      </div>
      <div class="col-lg-4 col-sm-4">
        <h3>Stay In Touch</h3>
        <a href="https://twitter.com/OpenStack" target="_blank" class="social-icons footer-twitter"></a>
        <a href="https://www.facebook.com/openstack" target="_blank" class="social-icons footer-facebook"></a>
        <a href="https://www.linkedin.com/company/openstack" target="_blank" class="social-icons footer-linkedin"></a>
        <a href="https://www.youtube.com/user/OpenStackFoundation" target="_blank" class="social-icons footer-youtube"></a>
        <p class="fine-print">
          The OpenStack project is provided under the
          <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache 2.0 license</a>. Openstack.org is powered by
          <a href="http://rackspace.com" target="_blank">Rackspace Cloud Computing</a>.
        </p>
      </div>
    </div>
  </div>
</footer>
<!-- jQuery -->
<script type="text/javascript" src="../_static/js/jquery-3.2.1.min.js"></script>

<!-- Bootstrap JavaScript -->
<script type="text/javascript" src="../_static/js/bootstrap.min.js"></script>

<!-- The rest of the JS -->
<script type="text/javascript" src="../_static/js/navigation.js"></script>

<!-- Docs JS -->
<script type="text/javascript" src="../_static/js/docs.js"></script>

<!-- Popovers -->
<script type="text/javascript" src="../_static/js/webui-popover.js"></script>

<!-- standard sphinx include libraries, which allow search highlighting -->
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/searchtools.js"></script>

<script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '2.11.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        SOURCELINK_SUFFIX: '.txt',
        HAS_SOURCE:  true
      };
</script>


<!-- Javascript for page -->
<script language="JavaScript">
/* build a description of this page including SHA, source location on git repo,
   build time and the project's launchpad bug tag. Set the HREF of the bug
   buttons */

    var lineFeed = "%0A";
    var gitURL = "Source: Can't derive source file URL";

    /* there have been cases where "pagename" wasn't set; better check for it */
        /* The URL of the source file on Git is based on the giturl variable
           in conf.py, which must be manually initialized to the source file
           URL in Git.
           "pagename" is a standard sphinx parameter containing the name of
           the source file, without extension.                             */

        var sourceFile = "user/demoapp" + ".rst";
        gitURL = "Source: https://git.openstack.org/cgit/openstack/cliff/tree/doc/source" + "/" + sourceFile;

    /* gitsha, project and bug_tag rely on variables in conf.py */
    var gitSha = "SHA: unknown";
        var bugProject = "python-cliff";
        var bugTitle = "Exploring the Demo App in cliff";
    var fieldTags = "";
        var useStoryboard = "";


    /* "last_updated" is the build date and time. It relies on the
       conf.py variable "html_last_updated_fmt", which should include
       year/month/day as well as hours and minutes                   */
    var buildstring = "Release: 2.11.0 on 2018-02-28 22:04";

    var fieldComment = encodeURI(buildstring) +
                       lineFeed + encodeURI(gitSha) +
                       lineFeed + encodeURI(gitURL) ;

    logABug(bugTitle, bugProject, fieldComment, fieldTags);
</script>

  </body>
</html>