Skip to content

Commit

Permalink
Error out on execute -C without statedir
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaarreell committed Jan 3, 2025
1 parent d8375ec commit a2d0872
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions newa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,7 @@ class CLIContext:
no_wait: bool = False
restart_request: list[str] = field(factory=list)
restart_result: list[str] = field(factory=list)
new_state_dir: bool = False

def enter_command(self, command: str) -> None:
self.logger.handlers[0].formatter = logging.Formatter(
Expand Down
7 changes: 7 additions & 0 deletions newa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ def main(click_context: click.Context,

ctx.logger.info(f'Using --state-dir={ctx.state_dirpath}')
if not ctx.state_dirpath.exists():
ctx.new_state_dir = True
ctx.logger.debug(f'State directory {ctx.state_dirpath} does not exist, creating...')
ctx.state_dirpath.mkdir(parents=True)

# extract YAML files from the given archive to state-dir
if extract_state_dir:
ctx.new_state_dir = False
if re.match('^https?://', extract_state_dir):
data = urllib.request.urlopen(extract_state_dir).read()
tf = tarfile.open(fileobj=io.BytesIO(data), mode='r:*')
Expand Down Expand Up @@ -985,6 +987,11 @@ def cmd_execute(
ctx.restart_result = restart_result
ctx.continue_execution = True

if ctx.continue_execution and ctx.new_state_dir:
ctx.logger.error(
'NEWA state-dir was not specified! Use --state-dir or similar option.')
sys.exit(1)

# initialize RP connection
rp_project = ctx.settings.rp_project
rp_url = ctx.settings.rp_url
Expand Down

0 comments on commit a2d0872

Please sign in to comment.