Skip to content

Commit

Permalink
allow for shpc config edit even if config file has an error
Browse files Browse the repository at this point in the history
this is do-able because we disable validation when edit is being
used.

Signed-off-by: vsoch <[email protected]>
  • Loading branch information
vsoch committed Jun 8, 2021
1 parent 5e2b88a commit 2d43610
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions shpc/client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ def main(args, parser, extra, subparser):

from shpc.main import get_client

cli = get_client(quiet=args.quiet, settings_file=args.settings_file)

# If nothing provided, show help
if not args.params:
print(subparser.format_help())
Expand All @@ -20,6 +18,11 @@ def main(args, parser, extra, subparser):
# The first "param" is either set of get
command = args.params.pop(0)

validate = True if not command == "edit" else False
cli = get_client(
quiet=args.quiet, settings_file=args.settings_file, validate=validate
)

# For each new setting, update and save!
if command == "edit":
return cli.settings.edit()
Expand Down
3 changes: 2 additions & 1 deletion shpc/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def get_client(quiet=False, **kwargs):
"""
# The name of the module
module = kwargs.get("module")
validate = kwargs.get("validate", True)

# Load user settings to add to client, and container technology
settings = Settings(kwargs.get("settings_file"))
settings = Settings(kwargs.get("settings_file"), validate)
container = kwargs.get("container_tech") or settings.container_tech

# Use the user provided module OR the default
Expand Down
2 changes: 1 addition & 1 deletion shpc/main/modules/templates/docker.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ proc ModulesHelp { } {
puts stderr " - {|module_name|}-shell:"
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint {{ shell }}{% if envfile %} --env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v . -w . <container>"
puts stderr " - {|module_name|}-exec:"
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint {{ shell }}{% if envfile %} --env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v . -w . <container> $*"
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint \"\" {% if envfile %} --env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %} -v . -w . <container> $*"
puts stderr " - {|module_name|}-inspect:"
puts stderr " {{ command }} inspect <container>"
{% if aliases %}{% for alias in aliases %} puts stderr " - {{ alias.name }}:"
Expand Down
5 changes: 3 additions & 2 deletions shpc/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,13 @@ class Settings(SettingsBase):
a dictionary-like class with extra functions.
"""

def __init__(self, settings_file):
def __init__(self, settings_file, validate=True):
"""
Create a new settings object, which requires a settings file to load
"""
self.load(settings_file)
self.validate()
if validate:
self.validate()

# Set an updated time, in case it's written back to file
self._settings["updated_at"] = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ")

0 comments on commit 2d43610

Please sign in to comment.