Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # A script to parse `espanso --help` recursively throughout all its levels.
- import subprocess
- import sys
- def parse_help(command):
- try:
- help_text = subprocess.check_output(command + ['--help'], stderr=subprocess.STDOUT, text=True)
- except subprocess.CalledProcessError as e:
- print(f"Error: Failed to get help for {' '.join(command)}. Make sure the command exists and supports --help option.")
- return
- print(help_text)
- # Parse for subcommands
- subcommands = []
- lines = iter(help_text.split('\n'))
- for line in lines:
- if line.strip().startswith('SUBCOMMANDS:'):
- subcommand_line = next(lines, '').strip()
- while subcommand_line:
- subcommand = subcommand_line.split()[0]
- subcommands.append(subcommand)
- subcommand_line = next(lines, '').strip()
- break
- # Recursively parse help for subcommands
- for subcommand in subcommands:
- print(f"\nSubcommand: {subcommand}\n{'='*len(subcommand)}")
- parse_help(command + [subcommand])
- if __name__ == "__main__":
- if len(sys.argv) != 2:
- print("Usage: python script.py <command>")
- sys.exit(1)
- command = sys.argv[1]
- parse_help([command])
Advertisement
Comments
-
- Usage:
- python parse_help.py espanso
-
- Parses `espanso --help` throughout all its levels.
Add Comment
Please, Sign In to add comment
Advertisement