def _verify_executable_exists(ctx: ProjectContext, alias: Optional[str]) -> bool: """Return true if an alias maps to a file in a context and provide user messaging.""" if alias is None: print('Cannot find an executable for a null alias.') return False if not ctx.has_registered_program(alias): print(f'No alias exists for {alias}') recommended: Optional[str] = mp.recommended_executable(mp.root_to_executable(alias)) if recommended is not None: choice: str = input(f'Use recommended path for alias "{alias}": {recommended} (saves in .crank) [y/N]? ') if choice == 'y': print(f'Setting alias {alias} -> {recommended}') if ctx.register_program(alias, recommended): ctx.save() return True print('Use `crank register ALIAS PATH` to register a program for use.') print('Example: crank register cmake "C:/Program Files/CMake/bin/cmake.exe"') return False program_path = ctx.path_for_program(alias) if not os.path.isfile(program_path): print(f'Executable path for {alias} does not exist at {program_path}') return False return True
def cmd_register(ctx: ProjectContext, args: argparse.Namespace) -> int: """Registers a new program for use in the given context.""" if os.path.isfile(args.path) or args.force: if args.dry_run: if ctx.has_registered_program(args.alias) and not args.override: print(f'Trying to override {ctx.path_for_program(args.alias)} of {args.alias} with {args.path}') return 1 else: print(f'Would have added alias {args.alias} -> {args.path}') return 0 else: if ctx.register_program(args.alias, args.path, args.override): return 0 return 1 print(f'No program exists at {args.path}.') return 1