Skip to content

Commit 39253d9

Browse files
committed
feat(cli): docopt subcommands
Setup command/subcommand pattern. Next will be the infrastucture for documenting these, using mkdocs and markdown.
1 parent f527c82 commit 39253d9

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

src/mako/cli/lib/docopt.mako

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
<%namespace name="util" file="../../lib/util.mako"/>\
2+
<%!
3+
from cli import mangle_subcommand
4+
%>\
25
<%def name="new(c)">\
36
docopt!(Args derive Debug, "
4-
Usage: ${util.program_name()} [options] (<OUTPUT-FILE>|-)
5-
${util.program_name()} --help
7+
Usage:
8+
% for resource in sorted(c.rta_map.keys()):
9+
<%
10+
mangled_method_names = [mangle_subcommand(method) for method in sorted(c.rta_map[resource])]
11+
assert mangled_method_names
12+
%>\
13+
${util.program_name()} ${mangle_subcommand(resource)} \
14+
% if len(mangled_method_names) > 1:
15+
(\
16+
% endif
17+
${'|'.join(mangled_method_names)}\
18+
% if len(mangled_method_names) > 1:
19+
)\
20+
% endif
621
7-
Options:
8-
--width <X> The width of the output image [default: 1024]
9-
--height <Y> The height of the output image [default: 1024]
10-
--samples-per-pixel <SAMPLES> Amount of samples per pixel. 4 means 16 over-samples [default: 1]
11-
--num-cores <NUM_CORES> Amount of cores to do the rendering on [default: 1]
12-
If this is not set, you may also use the RTRACEMAXPROCS
13-
environment variable, e.g. RTRACEMAXPROCS=4.
14-
The commandline always overrides environment variables.
15-
16-
<OUTPUT-FILE>|- Either a file with .tga extension, or - to write file to stdout
17-
"
18-
, flag_samples_per_pixel: u16
19-
, flag_height: u16
20-
, flag_width: u16
21-
, flag_num_cores: usize);
22+
% endfor # end for each resource
23+
${util.program_name()} --help
24+
");
2225
</%def>

src/mako/cli/main.rs.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
extern crate docopt;
1212
extern crate rustc_serialize;
1313

14-
<%docopt:new c="c"/>\
14+
${docopt.new(c)}\
1515

1616
fn main() {
1717
let _: Args = Args::docopt().decode().unwrap_or_else(|e| e.exit());

src/mako/lib/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import util
2+
3+
# transform name to be a suitable subcommand
4+
def mangle_subcommand(name):
5+
return util.camel_to_under(name).replace('_', '-').replace('.', '-')

0 commit comments

Comments
 (0)