Completed
Push — master ( 00af05...860b51 )
by Gonzalo
7s
created

parse_password_check_repo()   A

Complexity

Conditions 4

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
dl 0
loc 13
rs 9.2
1
# -*- coding: utf-8 -*-
2
# -----------------------------------------------------------------------------
3
# Copyright (c) The Spyder Development Team
4
#
5
# Licensed under the terms of the MIT License
6
# (See LICENSE.txt for details)
7
# -----------------------------------------------------------------------------
8
"""Common CLI utilities."""
9
10
# yapf: disable
11
12
from __future__ import print_function
13
14
# Standard library imports
15
import getpass
16
import sys
17
18
19
# yapf: enable
20
21
22
def add_common_parser_args(parser):
23
    """Parse CLI common login and repo arguments."""
24
    parser.add_argument(
25
        'repository',
26
        help="Repository name to generate the Changelog for, in the form "
27
        "user/repo or org/repo (e.g. spyder-ide/spyder)")
28
    parser.add_argument(
29
        '-u',
30
        '--username',
31
        action="store",
32
        dest="username",
33
        default='',
34
        help="Github user name")
35
    parser.add_argument(
36
        '-p',
37
        '--password',
38
        action="store",
39
        dest="password",
40
        default='',
41
        help="Github user password")
42
    parser.add_argument(
43
        '-t',
44
        '--token',
45
        action="store",
46
        dest="token",
47
        default='',
48
        help="Github access token")
49
50
    return parser
51
52
53
def parse_password_check_repo(options):
54
    """Check password and prompt if missing and check repo is provided."""
55
    if options.username and not options.password:
56
        password = getpass.getpass()
57
    else:
58
        password = options.password
59
60
    # Check if repo given
61
    if not options.repository:
62
        print('LOGHUB: Please define a repository name to this script. '
63
              'See its help')
64
        sys.exit(1)
65
    return password
66