Skip to content

Commit

Permalink
Merge pull request #153 from SubstraFoundation/common_output_option
Browse files Browse the repository at this point in the history
Common output option
  • Loading branch information
jmorel authored Apr 7, 2020
2 parents b670759 + dd1f429 commit 576b721
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 74 deletions.
75 changes: 30 additions & 45 deletions references/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -184,9 +183,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -225,9 +223,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -286,9 +283,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -327,9 +323,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -368,9 +363,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -405,9 +399,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand All @@ -432,9 +425,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -479,9 +471,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -516,9 +507,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand All @@ -541,9 +531,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -581,9 +570,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -654,9 +642,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -723,9 +710,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

Expand Down Expand Up @@ -833,9 +819,8 @@ Options:
user).

--verbose Enable verbose mode.
--yaml Display output as yaml.
--json Display output as json.
--pretty Pretty print output [default: True]
-o, --output [pretty|yaml|json]
Set output format [default: pretty]
--help Show this message and exit.
```

39 changes: 10 additions & 29 deletions substra/cli/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,35 +140,16 @@ def click_global_conf_log_level(f):


def click_global_conf_output_format(f):
"""Add json option to command."""
flags = [
click.option(
'--pretty', 'output_format',
flag_value='pretty',
expose_value=False,
default=True,
show_default=True,
callback=update_global_conf,
help='Pretty print output'
),
click.option(
'--json', 'output_format',
flag_value='json',
expose_value=False,
callback=update_global_conf,
help='Display output as json.'
),
click.option(
'--yaml', 'output_format',
flag_value='yaml',
expose_value=False,
callback=update_global_conf,
help='Display output as yaml.'
)
]
for flag in flags:
f = flag(f)
return f
"""Add output option to command."""
return click.option(
'-o', '--output', 'output_format',
type=click.Choice(['pretty', 'yaml', 'json']),
expose_value=False,
default='pretty',
show_default=True,
callback=update_global_conf,
help='Set output format'
)(f)


def click_global_conf(f):
Expand Down

0 comments on commit 576b721

Please sign in to comment.