Skip to content

Commit 30984fb

Browse files
committed
Print stagpy.__doc__ in cli help
1 parent 7c34113 commit 30984fb

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

stagpy/args.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from loam.tools import set_conf_str, create_complete_files
77
from loam.cli import Subcmd, CLIManager
88

9+
from . import __doc__ as doc_module
910
from . import conf, PARSING_OUT, load_mplstyle
1011
from . import commands, field, rprof, time_series, refstate, plates
1112
from .misc import baredoc
@@ -18,9 +19,14 @@ def _sub(cmd, *sections):
1819
return Subcmd(baredoc(cmd), *sections, func=cmd_func)
1920

2021

22+
def _bare_cmd():
23+
"""Print help message when no arguments are given."""
24+
print(doc_module)
25+
print('Run `stagpy -h` for usage')
26+
27+
2128
SUB_CMDS = OrderedDict((
22-
('common_', Subcmd('read and process StagYY binary data', 'common',
23-
func=lambda: print('stagpy -h for usage'))),
29+
('common_', Subcmd(doc_module, 'common', func=_bare_cmd)),
2430
('field', _sub(field, 'core', 'plot', 'scaling')),
2531
('rprof', _sub(rprof, 'core', 'plot', 'scaling')),
2632
('time', _sub(time_series, 'core', 'plot', 'scaling')),

tests/test_args.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
def test_no_args(capsys):
77
stagpy.args.parse_args([])()
88
output = capsys.readouterr()
9-
expected = 'stagpy -h for usage\n'
10-
assert output.out == expected
9+
expected = re.compile(
10+
r'StagPy is a tool to.*'
11+
r'Run `stagpy -h` for usage\n$',
12+
flags=re.DOTALL)
13+
assert expected.fullmatch(output.out)
1114

1215

1316
def test_help(capsys):
1417
with pytest.raises(SystemExit):
1518
stagpy.args.parse_args(['-h'])
1619
output = capsys.readouterr()
1720
expected = re.compile(
18-
r'^usage:.*\nread and process StagYY binary data.*'
21+
r'^usage:.*\nStagPy is a tool to.*'
1922
r'\npositional arguments.*\noptional arguments.*$',
2023
flags=re.DOTALL)
2124
assert expected.fullmatch(output.out)

0 commit comments

Comments
 (0)