Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stechuhr-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pandemic_Response
stechuhr-client
Commits
41bba04c
Commit
41bba04c
authored
4 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Add missing main to config
parent
f93e14b8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pyproject.toml
+1
-0
1 addition, 0 deletions
pyproject.toml
stechuhr_client/config.py
+88
-0
88 additions, 0 deletions
stechuhr_client/config.py
with
89 additions
and
0 deletions
pyproject.toml
+
1
−
0
View file @
41bba04c
...
...
@@ -20,6 +20,7 @@ pytest = "^5.2"
[tool.poetry.scripts]
stechuhr-client
=
"stechuhr_client.client:main"
config
=
"stechuhr_client.config:main"
[build-system]
...
...
This diff is collapsed.
Click to expand it.
stechuhr_client/config.py
+
88
−
0
View file @
41bba04c
...
...
@@ -290,6 +290,94 @@ def read_config(config_path: str) -> dict:
process_led_list_value
(
config
,
"
success_on_time
"
)
return
config
def
main
():
"""
Gets run only if config.py is called directly or via `poetry run config`
Entry point for the CLI application
"""
# List of available commands and their respective functions
commands
=
{
"
default
"
:
print_default
,
"
paths
"
:
print_paths
,
"
directories
"
:
print_directories
,
"
create
"
:
create_config
,
"
test
"
:
test
}
# List of available options
availaible_options
=
[
[
"
-h
"
,
"
--help
"
]
]
# If no argument has been passed display the help and exit
if
len
(
sys
.
argv
)
==
1
:
print_help
()
exit
()
# Extract the command arguments
command_args
=
[
c
for
c
in
sys
.
argv
[
1
:]
if
not
c
.
strip
().
startswith
(
"
-
"
)]
# Extract the short_options
short_options
=
[
c
.
lstrip
(
"
-
"
)
for
c
in
sys
.
argv
[
1
:]
if
c
.
strip
().
startswith
(
"
-
"
)
and
not
c
.
strip
().
startswith
(
"
--
"
)]
# Flatten the short_options to e.g. so -1234 will result in ["1", "2", "3", "4"]
short_options
=
[
item
for
sublist
in
short_options
for
item
in
sublist
]
# Extract the long options
long_options
=
[
c
.
lstrip
(
"
--
"
)
for
c
in
sys
.
argv
[
1
:]
if
c
.
strip
().
startswith
(
"
--
"
)]
errored
=
False
# Short Options
for
o
in
short_options
:
if
o
not
in
[
a
[
0
].
lstrip
(
"
-
"
)
for
a
in
availaible_options
]:
print
(
"
Error: the option
\"
-{}
\"
does not exist.
"
.
format
(
o
),
file
=
sys
.
stderr
)
errored
=
True
# Long Options
for
o
in
long_options
:
if
o
not
in
[
a
[
0
].
lstrip
(
"
--
"
)
for
a
in
availaible_options
]:
print
(
"
Error: the option
\"
--{}
\"
does not exist.
"
.
format
(
o
),
file
=
sys
.
stderr
)
errored
=
True
# If any of the above errored, exit. This allows to display all errors at once
if
errored
:
print
(
"
\n
Check the available commands and options below:
"
)
print
()
print_help
()
exit
()
# Currently we only handle a single command
if
len
(
command_args
)
==
1
:
command
=
sys
.
argv
[
1
]
# Short commands are allowed if they are not ambigous. E.g "te" will trigger "test"
if
not
any
([
c
.
startswith
(
command
.
strip
().
lower
())
for
c
in
commands
.
keys
()]):
# No fitting command has been found, print helpt and exit
print_help
()
exit
()
elif
len
([
c
for
c
in
commands
.
keys
()
if
c
.
startswith
(
command
.
strip
().
lower
())])
>
1
:
# More than one fitting command has been found, display this message
print
(
"
Ambiguous Input: There are {} commands starting with
\"
{}
\"
: {}
"
.
format
(
len
([
c
for
c
in
commands
.
keys
()
if
c
.
startswith
(
command
.
strip
().
lower
())]),
command
,
"
,
"
.
join
([
c
for
c
in
commands
.
keys
()
if
c
.
startswith
(
command
.
strip
().
lower
())])
))
else
:
# A command has been found:
choice
=
[
c
for
c
in
commands
.
keys
()
if
c
.
startswith
(
command
.
strip
().
lower
())][
0
]
# If there is a -h or --help option, display the function's docstring
# otherwise execute the function
if
"
h
"
in
short_options
or
"
help
"
in
long_options
:
print
(
"
Help: config {}
"
.
format
(
commands
[
choice
].
__name__
))
print
(
commands
[
choice
].
__doc__
)
else
:
commands
[
choice
]()
else
:
# If more than one command is given, display the help
print_help
()
def
test
():
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment