Skip to content

Commit aa2087f

Browse files
committed
Added new flag : -x to list commands exclusive to a platform
1 parent 93f62f2 commit aa2087f

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ options:
6868
-p PLATFORM, --platform PLATFORM
6969
Override the operating system [android, freebsd, linux, netbsd, openbsd, osx, sunos, windows, common]
7070
-l, --list List all available commands for operating system
71+
-x, --exclusive Use with --list and -p to list commands exclusive to the specfied platform
7172
-s SOURCE, --source SOURCE
7273
Override the default page source
7374
-c, --color Override color stripping

tldr.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,21 @@ def get_page(
382382
COMMAND_SPLIT_REGEX = re.compile(r'(?P<param>{{.+?}*}})')
383383
PARAM_REGEX = re.compile(r'(?:{{)(?P<param>.+?)(?:}})')
384384

385+
def get_exclusive_commands(platforms: List[str], language: Optional[List[str]] = None) -> List[str]:
386+
387+
common_commands = set(get_commands(['common'], language))
388+
exclusive_commands = set()
389+
390+
for platform in platforms:
391+
platform_commands = set(get_commands([platform], language))
392+
exclusive_commands.update(platform_commands - common_commands)
393+
394+
return sorted(exclusive_commands)
395+
385396

386397
def get_commands(platforms: Optional[List[str]] = None,
387-
language: Optional[str] = None) -> List[str]:
398+
language: Optional[str] = None,
399+
exclusive: bool = False) -> List[str]:
388400
if platforms is None:
389401
platforms = get_platform_list()
390402

@@ -394,6 +406,10 @@ def get_commands(platforms: Optional[List[str]] = None,
394406
languages = get_language_list()
395407

396408
commands = []
409+
410+
if exclusive:
411+
return get_exclusive_commands(platforms, language);
412+
397413
if get_cache_dir().exists():
398414
for platform in platforms:
399415
for language in languages:
@@ -610,6 +626,11 @@ def create_parser() -> ArgumentParser:
610626
action='store_true',
611627
help="List all available commands for operating system")
612628

629+
parser.add_argument('-x', '--exclusive',
630+
default=False,
631+
action='store_true',
632+
help="Use with --list and -p to list commands exclusive to the specfied platform")
633+
613634
parser.add_argument('-s', '--source',
614635
default=PAGES_SOURCE_LOCATION,
615636
type=str,
@@ -714,7 +735,8 @@ def main() -> None:
714735
parser.print_help(sys.stderr)
715736
sys.exit(1)
716737
if options.list:
717-
print('\n'.join(get_commands(options.platform, options.language)))
738+
print('\n'.join(get_commands(options.platform, options.language, options.exclusive)))
739+
718740
elif options.render:
719741
for command in options.command:
720742
file_path = Path(command)

0 commit comments

Comments
 (0)