Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ options:
-p PLATFORM, --platform PLATFORM
Override the operating system [android, freebsd, linux, netbsd, openbsd, osx, sunos, windows, common]
-l, --list List all available commands for operating system
-x, --exclusive Use with --list and -p to list commands exclusive to the specfied platform
Comment thread
sebastiaanspeck marked this conversation as resolved.
Outdated
-s SOURCE, --source SOURCE
Override the default page source
-c, --color Override color stripping
Expand Down
26 changes: 24 additions & 2 deletions tldr.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,21 @@ def get_page(
COMMAND_SPLIT_REGEX = re.compile(r'(?P<param>{{.+?}*}})')
PARAM_REGEX = re.compile(r'(?:{{)(?P<param>.+?)(?:}})')

def get_exclusive_commands(platforms: List[str], language: Optional[List[str]] = None) -> List[str]:

common_commands = set(get_commands(['common'], language))
exclusive_commands = set()

for platform in platforms:
platform_commands = set(get_commands([platform], language))
exclusive_commands.update(platform_commands - common_commands)

return sorted(exclusive_commands)


def get_commands(platforms: Optional[List[str]] = None,
language: Optional[str] = None) -> List[str]:
language: Optional[str] = None,
exclusive: bool = False) -> List[str]:
if platforms is None:
platforms = get_platform_list()

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

commands = []

if exclusive:
return get_exclusive_commands(platforms, language);

if get_cache_dir().exists():
for platform in platforms:
for language in languages:
Expand Down Expand Up @@ -610,6 +626,11 @@ def create_parser() -> ArgumentParser:
action='store_true',
help="List all available commands for operating system")

parser.add_argument('-x', '--exclusive',
default=False,
action='store_true',
help="Use with --list and -p to list commands exclusive to the specfied platform")
Comment thread
sebastiaanspeck marked this conversation as resolved.
Outdated

parser.add_argument('-s', '--source',
default=PAGES_SOURCE_LOCATION,
type=str,
Expand Down Expand Up @@ -714,7 +735,8 @@ def main() -> None:
parser.print_help(sys.stderr)
sys.exit(1)
if options.list:
print('\n'.join(get_commands(options.platform, options.language)))
print('\n'.join(get_commands(options.platform, options.language, options.exclusive)))

elif options.render:
for command in options.command:
file_path = Path(command)
Expand Down