Skip to content

Commit 17166c2

Browse files
committed
Added --version option
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
1 parent 4f80da5 commit 17166c2

File tree

6 files changed

+16
-27
lines changed

6 files changed

+16
-27
lines changed

.github/workflows/black-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
- name: Check formatting with black
3232
run: |
3333
shopt -s globstar
34-
black --check cfengine_cli/ tests/
34+
black --check .

.github/workflows/black-format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Reformat with black
2525
run: |
2626
shopt -s globstar
27-
black cfengine_cli/ tests/ > black_output.txt 2>&1
27+
black . > black_output.txt 2>&1
2828
- name: Check if there are changes
2929
run: |
3030
git diff --exit-code || touch git_diff_exists

cfengine_cli/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from cfengine_cli.shell import user_command
22
from cfengine_cli.paths import bin
3-
from cfengine_cli.version import string as version_string
3+
from cfengine_cli.version import cfengine_cli_version_string
44

55

66
def run() -> int:
@@ -22,5 +22,5 @@ def help() -> int:
2222

2323

2424
def version() -> int:
25-
print(version_string())
25+
print(cfengine_cli_version_string())
2626
return 0

cfengine_cli/main.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
import sys
44

55
from cf_remote import log
6-
from cfengine_cli import version
6+
from cfengine_cli.version import cfengine_cli_version_string
77
from cfengine_cli import commands
88
from cfengine_cli.utils import UserError
99

1010

11-
def print_version_info():
12-
print("CFEngine CLI version %s" % version.string())
13-
14-
1511
def _get_arg_parser():
1612
ap = argparse.ArgumentParser(
1713
description="Human-oriented CLI for interacting with CFEngine tools",
@@ -27,10 +23,9 @@ def _get_arg_parser():
2723
ap.add_argument(
2824
"--version",
2925
"-V",
30-
help="Print or specify version",
31-
nargs="?",
32-
type=str,
33-
const=True,
26+
help="Print version number",
27+
action="version",
28+
version=f"{cfengine_cli_version_string()}",
3429
)
3530

3631
command_help_hint = (
@@ -65,6 +60,8 @@ def get_args():
6560

6661

6762
def run_command_with_args(command, _) -> int:
63+
if not command:
64+
raise UserError("No command specified - try 'cfengine help'")
6865
if command == "run":
6966
return commands.run()
7067
if command == "report":
@@ -73,7 +70,7 @@ def run_command_with_args(command, _) -> int:
7370
return commands.help()
7471
if command == "version":
7572
return commands.version()
76-
raise UserError("Unknown command: '{}'".format(command))
73+
raise UserError(f"Unknown command: '{command}'")
7774

7875

7976
def validate_command(_command, _args):

cfengine_cli/version.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33

4-
def string():
4+
def cfengine_cli_version_number():
55
try:
66
with open(os.path.dirname(__file__) + "/VERSION", "r", encoding="utf-8") as fh:
77
version = fh.read().strip()
@@ -10,3 +10,7 @@ def string():
1010
except:
1111
pass
1212
return "unknown (git checkout)"
13+
14+
15+
def cfengine_cli_version_string():
16+
return f"CFEngine CLI {cfengine_cli_version_number()}"

run_tests.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)