Commit 34e42e78 authored by Adrian DC's avatar Adrian DC
Browse files

feat: implement #87: add support for --version informations

 * Based on the same --version output syntax than Python pip
parent 10d415fa
Loading
Loading
Loading
Loading
+1 −0
Changes for README.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ gitlabci-local: Launch .gitlab-ci.yml jobs locally (aliases: gcil)
| optional arguments   |                                                                                   |
| -------------------- | --------------------------------------------------------------------------------- |
| -h, --help           | Show this help message                                                            |
| --version            | Show the current version                                                          |
| -q, --quiet          | Hide jobs execution context                                                       |
| -c CONFIGURATION     | Path to the .gitlab-ci.yml configuration file or folder                           |
| -B, --no-before      | Disable before_script executions                                                  |
+22 −1
Changes for gitlabci_local/main.py: 22 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
# Libraries
import argparse
import colored
import importlib.metadata
import os
import sys

@@ -35,9 +36,13 @@ def main():
    # Arguments enumerations definitions
    networksEnum = ['bridge', 'host', 'none']

    # Arguments optional definitions
    # Arguments internal definitions
    parser.add_argument('-h', '--help', dest='help', action='store_true',
                        help='Show this help message')
    parser.add_argument('--version', dest='version', action='store_true',
                        help='Show the current version')

    # Arguments optional definitions
    parser.add_argument('-q', '--quiet', dest='quiet', action='store_true',
                        help='Hide jobs execution context')
    parser.add_argument('-c', dest='configuration', default='.gitlab-ci.yml',
@@ -104,12 +109,28 @@ def main():

    # Arguments parser
    options = parser.parse_args()

    # Help informations
    if options.help:
        print(' ')
        parser.print_help()
        print(' ', flush=True)
        sys.exit(0)

    # Version informations
    if options.version:
        name = __name__.split('.')[0]
        version = '0.0.0'
        try:
            version = importlib.metadata.version(name)
        except importlib.metadata.PackageNotFoundError:
            pass
        print(
            '%s %s from %s (python %s.%s)' %
            (name, version, __file__, sys.version_info.major, sys.version_info.minor),
            flush=True)
        sys.exit(0)

    # Prepare configuration
    if os.path.isdir(options.configuration):
        options.configuration = os.path.join(options.configuration, '.gitlab-ci.yml')