Skip to content

Commit

Permalink
Make -c and -f mutually exlusive
Browse files Browse the repository at this point in the history
Also removes dead code since --color and --no-color are ensured by argparse
to be mutually exclusive.

Move --version to the end of the command line params in -h
  • Loading branch information
ChaoticMind committed Mar 19, 2020
1 parent f58dbef commit 09963d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 7 additions & 6 deletions gpustat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ def main(*argv):
parser.add_argument('-a', '--show-all', action='store_true',
help='Display all gpu properties above')

parser.add_argument('-c', '--show-cmd', action='store_true',
parser_cmd = parser.add_mutually_exclusive_group()
parser_cmd.add_argument('-c', '--show-cmd', action='store_true',
help='Display cmd name of running process')
parser.add_argument(
parser_cmd.add_argument(
'-f', '--show-full-cmd', action='store_true',
help='Display full command and cpu stats of running process'
)
Expand All @@ -93,10 +94,6 @@ def main(*argv):
help='Display PID of running process')
parser.add_argument('-F', '--show-fan-speed', '--show-fan',
action='store_true', help='Display GPU fan speed')
parser.add_argument('--json', action='store_true', default=False,
help='Print all the information in JSON format')
parser.add_argument('-v', '--version', action='version',
version=('gpustat %s' % __version__))
parser.add_argument(
'-e', '--show-codec', nargs='?', const='enc,dec',
choices=['enc', 'dec', 'enc,dec'],
Expand All @@ -107,6 +104,8 @@ def main(*argv):
choices=['', 'draw', 'limit', 'draw,limit', 'limit,draw'],
help='Show GPU power usage or draw (and/or limit)'
)
parser.add_argument('--json', action='store_true', default=False,
help='Print all the information in JSON format')
parser.add_argument(
'-i', '--interval', '--watch', nargs='?', type=float, default=0,
help='Use watch mode if given; seconds to wait between updates'
Expand All @@ -123,6 +122,8 @@ def main(*argv):
'--debug', action='store_true', default=False,
help='Allow to print additional informations for debugging.'
)
parser.add_argument('-v', '--version', action='version',
version=('gpustat %s' % __version__))
args = parser.parse_args(argv[1:])
if args.show_all:
args.show_cmd = True
Expand Down
4 changes: 0 additions & 4 deletions gpustat/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,6 @@ def print_formatted(self, fp=sys.stdout, force_color=False, no_color=False,
eol_char=os.linesep,
):
# ANSI color configuration
if force_color and no_color:
raise ValueError("--color and --no_color can't"
" be used at the same time")

if force_color:
t_color = Terminal(force_styling=True)

Expand Down

0 comments on commit 09963d5

Please sign in to comment.