diff --git a/cli/__main__.py b/cli/__main__.py index 60452c1..dc8f998 100644 --- a/cli/__main__.py +++ b/cli/__main__.py @@ -59,11 +59,24 @@ if __name__ == '__main__': profile_observer.subscribe('disabled', lambda event: pprint.pp((__sanitize_profile(event.subject), 'Disabled')) if event.meta.get('explicitly') else None) profile_observer.subscribe('enabled', lambda event: pprint.pp((__sanitize_profile(event.subject), 'Enabled'))) - def __get_name(): - return metadata.packages_distributions()['cli'][0] + def __get_distribution(): - def __get_version(): - return metadata.version(__get_name()) + for candidate in metadata.distributions(): + + if 'cli' not in candidate.name: + continue + + candidate_files = candidate.files + + if candidate_files is None: + continue + + for distribution_file in candidate_files: + + if distribution_file.parts[0] == 'cli': + return candidate + + return None def __parse_composite_argument(argument: str, first_key: str, second_key: str, separator: str = ':'): return dict(zip([first_key, second_key], argument.split(separator) + [''])) @@ -92,6 +105,7 @@ if __name__ == '__main__': sys.__excepthook__(identifier, message, traceback) sys.excepthook = __handle_exception + distribution = __get_distribution() pristine_parser = argparse.ArgumentParser(add_help=False) pristine_parser.add_argument('--pristine', '-p', action='store_true') @@ -105,8 +119,8 @@ if __name__ == '__main__': profile_state_protection_parser = argparse.ArgumentParser(add_help=False) profile_state_protection_parser.add_argument('--without-profile-state-protection', action='store_true') - main_parser = argparse.ArgumentParser(prog=__get_name()) - main_parser.add_argument('--version', '-v', action='version', version=f'{__get_name()} v{__get_version()}') + main_parser = argparse.ArgumentParser(prog=distribution.name) + main_parser.add_argument('--version', '-v', action='version', version=f'{distribution.name} v{distribution.version}') main_subparsers = main_parser.add_subparsers(title='commands', dest='command') profile_parser = main_subparsers.add_parser('profile')