Skip to content

Commit

Permalink
Merge pull request #45 from fosslight/develop
Browse files Browse the repository at this point in the history
Add function for print package version
  • Loading branch information
soimkim authored Jan 4, 2022
2 parents 8e30826 + 9e9c225 commit f4812a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/fosslight_util/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import sys
import pkg_resources

_HELP_MESSAGE_COMMON = """
_______ _______ _______ _______ ___ ___ _______ __ __ _______
Expand All @@ -27,3 +28,13 @@ def print_help_msg(self, exitopt):

if exitopt:
sys.exit()


def print_package_version(pkg_name, msg="", exitopt=True):
if msg == "":
msg = f"{pkg_name} Version :"
cur_version = pkg_resources.get_distribution(pkg_name).version
print(f'{msg} {cur_version}')

if exitopt:
sys.exit(0)
6 changes: 4 additions & 2 deletions tests/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
from fosslight_util.help import PrintHelpMsg
from fosslight_util.help import PrintHelpMsg, print_package_version


def main():
Expand All @@ -12,7 +12,9 @@ def main():
Test Test Test
"""
helpMsg = PrintHelpMsg(_HELP_MESSAGE_TEST)
helpMsg.print_help_msg(True)
helpMsg.print_help_msg(False)

print_package_version("fosslight_util", "FOSSLight Util Version")


if __name__ == '__main__':
Expand Down

0 comments on commit f4812a3

Please sign in to comment.