Skip to content

Commit

Permalink
fix small issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Jan 12, 2024
1 parent 759a6f5 commit 968c8e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/makim/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def main(
is_flag=True,
help='Execute the command in dry mode',
),
verbose: bool = typer.Option(
None,
'--verbose',
is_flag=True,
help='Execute the command in verbose mode',
),
) -> None:
"""Process envers for specific flags, otherwise show the help menu."""
typer.echo(f'Makim file: {file}')
Expand Down Expand Up @@ -226,12 +232,14 @@ def extract_root_config() -> Dict[str, str | bool]:
'--dry-run': 0,
'--file': 1,
'--help': 0, # not necessary to store this value
'--verbose': 0,
'--version': 0, # not necessary to store this value
}

# default values
makim_file = '.makim.yaml'
dry_run = False
verbose = False

try:
idx = 0
Expand All @@ -242,9 +250,10 @@ def extract_root_config() -> Dict[str, str | bool]:

if arg == '--file':
makim_file = params[idx + 1]

elif arg == '--dry-run':
dry_run = True
elif arg == '--verbose':
verbose = True

idx += 1 + root_args_values_count[arg]
except Exception:
Expand All @@ -259,6 +268,7 @@ def extract_root_config() -> Dict[str, str | bool]:
return {
'file': makim_file,
'dry_run': dry_run,
'verbose': verbose,
}


Expand All @@ -269,6 +279,7 @@ def run_app() -> None:
makim.load(
file=cast(str, root_config.get('file', '.makim.yaml')),
dry_run=cast(bool, root_config.get('dry_run', False)),
verbose=cast(bool, root_config.get('verbose', False)),
)

# create targets data
Expand Down
10 changes: 5 additions & 5 deletions src/makim/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Makim(PrintPlugin):

file: str = '.makim.yaml'
dry_run: bool = False
verbose: bool = False
global_data: dict = {}
shell_app: sh.Command = sh.xonsh

Expand Down Expand Up @@ -342,8 +343,6 @@ def _run_dependencies(self, args: dict):
args_dep_original = {
'file': args['file'],
'help': args.get('help', False),
'verbose': args.get('verbose', False),
'dry-run': args.get('dry-run', False),
'version': args.get('version', False),
'args': {},
}
Expand Down Expand Up @@ -393,7 +392,7 @@ def _run_dependencies(self, args: dict):
args=original_args_clean, env=self.env_scoped
)
if not yaml.safe_load(result):
if args.get('verbose'):
if self.verbose:
self._print_info(
'[II] Skipping dependency: '
f'{dep_data.get("target")}'
Expand Down Expand Up @@ -453,7 +452,7 @@ def _run_command(self, args: dict):

cmd = unescape_template_tag(str(cmd))
cmd = Template(cmd).render(args=args_input, env=env, vars=variables)
if args.get('verbose'):
if self.verbose:
self._print_info('=' * 80)
self._print_info(
'TARGET: ' + f'{self.group_name}.{self.target_name}'
Expand All @@ -477,10 +476,11 @@ def _run_command(self, args: dict):

# public methods

def load(self, file: str, dry_run: bool = False):
def load(self, file: str, dry_run: bool = False, verbose: bool = False):
"""Load makim configuration."""
self.file = file
self.dry_run = dry_run
self.verbose = verbose

self._load_config_data()
self._verify_config()
Expand Down

0 comments on commit 968c8e1

Please sign in to comment.