Light to use argument parser for cli tools. This is basically reinventing a wheel, but argparse felt cumbersome to use and some other options I looked up didn't seem attractive to me either. So, I decided to make a new one with the goal that I wouldn't need to sacrifice anything even when writing a really small script that could just index sys.argv.
Install with pip install lightparse
Below is an example dummy program using lightparse for argument parsing:
""" Test dummy program for lightparse. """ import sys import os from lightparse import Parser, SubcommandParser from lightparse.mappers import file_exists from lightparse.matrixprinter import print_matrix, true_false_colourer def main(): """Main""" parser = Parser( ).pos( "key", "word" ).opt({ "-f": "file", "-u": "user", # "-lkj": "disables combine", # "--too-wide-argument-to-have-the-help-function": "wide", }).fla({ "-q": "quir", }).map({ "file": file_exists, "user": int, }).describe( """ Description of what the program does. Would need to implement some fancy formatting for the text to allow easy writing of paragraphs. Argparse paragraphing is not that convinient, so I'm wanting to create something easier to use. """, { "key": "Key for what?", "file": "File for something?", "quir": """Lorem ipsum dolorsit amet, consectetur adipiscing elit. Vestibulum venenatis sitamet ex ac lacinia. Donec eros orci, cursus nonmauris a, semper facilisis nisi.""", # "unused": "Should probably raise exception for this.", }) bpar = Parser() topparser = SubcommandParser( ).sub({ "a": parser, "b": bpar, }).opt({ "--common": "common", }).describe( """ Tool with two subcommands: a and b. """, { "a": "subcommand a", "b": "and the subcommand b", "common": "common option", }) parser.behaviour.variable_arguments = True subcommand, args = topparser.parse(sys.argv[1:]) print("subcommand: {}".format(subcommand)) print_matrix( args.__dict__.items(), header=["variable", "value"], separators=(" | ", "-"), colourer=true_false_colourer) if __name__ == "__main__": main()