Skip to content

Commit 04ddd8a

Browse files
committed
Use _create_base_argument_parser in viewer.py
Change standard arguments definition to be defined using logger._create_base_argument_parser instead of manually defining them in this module.
1 parent e42f1f8 commit 04ddd8a

File tree

1 file changed

+11
-43
lines changed

1 file changed

+11
-43
lines changed

can/viewer.py

+11-43
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131

3232
import can
3333
from can import __version__
34-
from .logger import _create_bus, _parse_filters, _append_filter_argument
34+
from .logger import (
35+
_create_bus,
36+
_parse_filters,
37+
_append_filter_argument,
38+
_create_base_argument_parser,
39+
)
3540

3641

3742
logger = logging.getLogger("can.serial")
@@ -282,7 +287,7 @@ def draw_can_bus_message(self, msg, sorting=False):
282287
previous_byte_values[i] = b
283288
else:
284289
data_color = color
285-
text = "{:02X}".format(b)
290+
text = f"{b:02X}"
286291
self.draw_line(self.ids[key]["row"], col, text, data_color)
287292

288293
if self.data_structs:
@@ -402,6 +407,10 @@ def parse_args(args):
402407
allow_abbrev=False,
403408
)
404409

410+
# Generate the standard arguments:
411+
# Channel, bitrate, data_bitrate, interface, app_name, CAN-FD support
412+
_create_base_argument_parser(parser)
413+
405414
optional = parser.add_argument_group("Optional arguments")
406415

407416
optional.add_argument(
@@ -415,31 +424,6 @@ def parse_args(args):
415424
version="%(prog)s (version {version})".format(version=__version__),
416425
)
417426

418-
# Copied from: can/logger.py
419-
optional.add_argument(
420-
"-b",
421-
"--bitrate",
422-
type=int,
423-
help="""Bitrate to use for the given CAN interface""",
424-
)
425-
426-
optional.add_argument("--fd", help="Activate CAN-FD support", action="store_true")
427-
428-
optional.add_argument(
429-
"--data_bitrate",
430-
type=int,
431-
help="Bitrate to use for the data phase in case of CAN-FD.",
432-
)
433-
434-
optional.add_argument(
435-
"-c",
436-
"--channel",
437-
help="""Most backend interfaces require some sort of channel.
438-
For example with the serial interface the channel might be a rfcomm device: "/dev/rfcomm0"
439-
with the socketcan interfaces valid channel examples include: "can0", "vcan0".
440-
(default: use default for the specified interface)""",
441-
)
442-
443427
optional.add_argument(
444428
"-d",
445429
"--decode",
@@ -484,14 +468,6 @@ def parse_args(args):
484468

485469
_append_filter_argument(optional, "-f")
486470

487-
optional.add_argument(
488-
"-i",
489-
"--interface",
490-
dest="interface",
491-
help="R|Specify the backend CAN interface to use.",
492-
choices=sorted(can.VALID_INTERFACES),
493-
)
494-
495471
optional.add_argument(
496472
"-v",
497473
action="count",
@@ -501,14 +477,6 @@ def parse_args(args):
501477
default=2,
502478
)
503479

504-
# suppressed as the user doesn't need to change it
505-
optional.add_argument(
506-
"--app_name",
507-
dest="app_name",
508-
help=argparse.SUPPRESS,
509-
default="python-can-viewer",
510-
)
511-
512480
# Print help message when no arguments are given
513481
if not args:
514482
parser.print_help(sys.stderr)

0 commit comments

Comments
 (0)