def main(): """Launcher for the CLI.""" opt_parser = metomi.rose.opt_parse.RoseOptionParser() opt_parser.add_my_options() opts, args = opt_parser.parse_args(sys.argv[1:]) reporter = Reporter(opts.verbosity - opts.quietness) is_top_level = False if len(args) > 1: reporter.report('Only one argument accepted\n', level=Reporter.FAIL) sys.exit(1) if len(args) == 0: key = ROSE_INSTALL_ROOT / 'etc' path = ResourceLocator(paths=[ROSE_INSTALL_ROOT]).locate('etc') is_top_level = True else: key = args[0] try: path = ResourceLocator().locate(key) except ResourceError: reporter.report('Resource not found\n', level=Reporter.FAIL) sys.exit(1) if path.is_file(): print(path) elif path.is_dir(): print(f'{key}/') for item in path.iterdir(): if is_top_level: item = item.relative_to(path) else: item = item.relative_to(path.parent) print(f' {item}')
def main(): """Launcher for the CLI.""" opt_parser = metomi.rose.opt_parse.RoseOptionParser( usage='rose resource RESOURCE_PATH', description=''' Display the path of resources in the Rose Python installation. * If the requested resource exists and is a file its path is printed. * If the requested resource exists and is a directory it is listed. Provide no arguments to see a list of top-level resources. EXAMPLES # List top-level resources: $ rose resource # List the contents of the "syntax" directory: $ rose resource syntax # Extract the Rose syntax file for the Vim text editor: $ rose resource syntax/rose-conf.vim ''', epilog=''' ARGUMENTS RESOURCE_PATH Path of the resource to extract. Run `rose resource` to see the list of resources. ''', ) opt_parser.add_my_options() opts, args = opt_parser.parse_args() reporter = Reporter(opts.verbosity - opts.quietness) is_top_level = False if len(args) > 1: reporter.report('Only one argument accepted\n', level=Reporter.FAIL) sys.exit(1) if len(args) == 0: key = ROSE_INSTALL_ROOT / 'etc' path = ResourceLocator(paths=[ROSE_INSTALL_ROOT]).locate('etc') is_top_level = True else: key = args[0] try: path = ResourceLocator().locate(key) except ResourceError: reporter.report('Resource not found\n', level=Reporter.FAIL) sys.exit(1) if path.is_file(): print(path) elif path.is_dir(): print(f'{key}/') for item in path.iterdir(): if is_top_level: item = item.relative_to(path) else: item = item.relative_to(path.parent) print(f' {item}')