Ofer Koren
1 min readDec 15, 2019

--

An alternative to click is https://github.com/tomerfiliba/plumbum, which uses classes to define hierarchies of cli commands:

import logging
from plumbum import cli

class MyCompiler(cli.Application):
verbose = cli.Flag(["-v", "--verbose"], help = "Enable verbose mode")
include_dirs = cli.SwitchAttr("-I", list = True, help = "Specify include directories")

@cli.switch("--loglevel", int)
def set_log_level(self, level):
"""Sets the log-level of the logger"""
logging.root.setLevel(level)

def main(self, *srcfiles):
print("Verbose:", self.verbose)
print("Include dirs:", self.include_dirs)
print("Compiling:", srcfiles)

if __name__ == "__main__":
MyCompiler.run()

I find the decoration method limited as the scale of the application grows.

--

--

Ofer Koren
Ofer Koren

Written by Ofer Koren

A pythonist at heart, dabbling in Devops and Automations of various kinds

No responses yet