Verified Commit e4a21d1b authored by Adrian DC's avatar Adrian DC
Browse files

feat(git_pu): implement '-y/--yes' and '-n/--no' confirmation flags

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 6765387c
Loading
Loading
Loading
Loading
Loading
+57 −5
Changes for src/tools/git_pu.py: 57 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -9,7 +9,8 @@ from argparse import (
)
from shutil import get_terminal_size
from sys import exit as sys_exit
from typing import List
from time import sleep
from typing import List, Optional

# Modules libraries
from questionary import (
@@ -37,6 +38,7 @@ def git_pu(
    no_verify: bool,
    ref: str,
    force: bool,
    confirmation: Optional[bool] = None,
) -> int:

    # Variables
@@ -125,7 +127,14 @@ def git_pu(
                f'{Colors.RESET}',
                end='',
            )
            if questionary_press_any_key_to_continue(
            Platform.flush()
            if confirmation is True and (not risky or force):
                print(' (Confirmed by argument)')
                Platform.flush()
                sleep(1)
            elif confirmation is False:
                return -3
            elif questionary_press_any_key_to_continue(
                    message='',
                    style=None,
            ).ask() is None:
@@ -152,7 +161,14 @@ def git_pu(
                f'{Colors.RESET}',
                end='',
            )
            if questionary_press_any_key_to_continue(
            Platform.flush()
            if confirmation is True and (not risky or force):
                print(' (Confirmed by argument)')
                Platform.flush()
                sleep(1)
            elif confirmation is False:
                return -4
            elif questionary_press_any_key_to_continue(
                    message='',
                    style=None,
            ).ask() is None:
@@ -210,7 +226,17 @@ def git_pu(
            f'{Colors.RESET}',
            end='',
        )
        if not questionary_confirm(
        if confirmation is True and (not risky or force):
            print(' (Confirmed by argument)')
            Platform.flush()
            sleep(1)
        elif confirmation is False:
            print(' (Canceled by argument)')
            print(' ')
            Platform.flush()
            sleep(1)
            return 0
        elif not questionary_confirm(
                message='',
                default=not risky,
                qmark='',
@@ -218,11 +244,13 @@ def git_pu(
                auto_enter=True,
        ).ask():
            print(' ')
            Platform.flush()
            return 0

    # Selector interruption
    except KeyboardInterrupt:
        print(' ')
        Platform.flush()
        return -5

    # Push to remote
@@ -238,6 +266,7 @@ def git_pu(
def main() -> None:

    # Variables
    confirmation: Optional[bool]
    group: _ArgumentGroup
    result: int

@@ -309,6 +338,20 @@ def main() -> None:
        action='store_true',
        help='Validate result by requesting user input',
    )
    group.add_argument(
        '-y',
        '--yes',
        dest='yes',
        action='store_true',
        help='Automatic yes to user inputs',
    )
    group.add_argument(
        '-n',
        '--no',
        dest='no',
        action='store_true',
        help='Automatic no to user inputs',
    )
    group.add_argument(
        'remote',
        nargs='?',
@@ -345,6 +388,14 @@ def main() -> None:
        settings=settings,
    )

    # Prepare confirmation
    if options.no:
        confirmation = False
    elif options.yes:
        confirmation = True
    else:
        confirmation = None

    # Iterate over remotes
    for remote in Tools.git_remotes() if options.all else [
            options.remote,
@@ -363,6 +414,7 @@ def main() -> None:
                no_verify=options.no_verify,
                ref=options.ref,
                tags=options.tags,
                confirmation=confirmation,
            )

            # Validate result
@@ -374,7 +426,7 @@ def main() -> None:
        updates.check()

    # Validate result
    if options.validate:
    if options.validate and not options.yes:
        print(
            f'{Colors.YELLOW} {Tools.NAME}:'
            f'{Colors.GREEN if result >= 0 else Colors.RED} Press any key to continue...'