def initialize(self, log: jk_logging.AbstractLogger) -> jk_argparsing.ArgsParser: # initialize argument parser ap = jk_argparsing.ArgsParser( self.appName + " " + self.shortAppParamInfoImpl(), self.shortAppDescriptionImpl()) # set defaults ap.optionDataDefaults.set("bShowHelp", False) ap.optionDataDefaults.set("bShowVersion", False) ap.optionDataDefaults.set("bVerbose", False) ap.optionDataDefaults.set("bSimulate", False) ap.optionDataDefaults.set("bForce", False) # arguments ap.createOption("h", "help", "Display this help text and then exit.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: parsedArgs.optionData.set("bShowHelp", True) ap.createOption(None, "version", "Display the version of this software and then exit.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: parsedArgs.optionData.set("bShowVersion", True) ap.createOption("v", "verbose", "Generate verbose output.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: parsedArgs.optionData.set("bVerbose", True) ap.createOption("f", "force", "Enforce changes though there might be some aspects inappropriate for such kind of action.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: parsedArgs.optionData.set("bForce", True) # not used right now #ap.createOption("s", "simulate", "Simulate the specified action instead of performing it.").onOption = \ # lambda argOption, argOptionArguments, parsedArgs: parsedArgs.optionData.set("bSimulate", True) # return codes ap.createReturnCode(0, "Operation successfully completed.") ap.createReturnCode(1, "An error occurred.") self.initializeImpl(ap, log) for cmd in self.__cmds.values(): cmd.registerCmd(ap) return ap
def cli(self, appPath: str, verbosityLevel: int = 1): ap = jk_argparsing.ArgsParser(os.path.basename(appPath), "Runs Python based tasks.") ap.optionDataDefaults.set("help", False) ap.optionDataDefaults.set("verbosityLevel1", 0) ap.optionDataDefaults.set("verbosityLevel2", 0) ap.createOption("h", "help", "Display this help text.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("help", True) ap.createOption(None, "verbose", "Be verbose and print some information.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("verbosityLevel1", 1) ap.createOption(None, "very-verbose", "Be even more verbose and print a lot of detailed information.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("verbosityLevel2", 2) ap.titleCommandsStd = "Standard Commands" ap.createCommand("help", "Displays this help text.") """ ap.createCommand("pypine-ext-ls", "List all PyPine extensions installed.") ap.createCommand("pypine-ext-search", "Search for PyPine extensions online.").expectString("key", minLength=1) """ ap.titleCommandsExtra = "Task Commands" self.initializeArgsParser(ap) for taskName in self.__tasks.keys(): description, pipe = self.__tasks[taskName] if not ap.hasCommand(taskName): ap.createExtraCommand(taskName, description) ap.createAuthor("Jürgen Knauth", "*****@*****.**", "PyPine framework") # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # try install bash completion file appPath = os.path.abspath(appPath) ap.installLocalBashCompletion(appPath) # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # parse command line arguments parsedArgs = ap.parse() # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # maybe: show help if ("help" in parsedArgs.programArgs) or parsedArgs.optionData["help"]: ap.showHelp() return # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * """ if ("pypine-ext-ls" in parsedArgs.programArgs) or parsedArgs.optionData["pyPineExt-listInstalled"]: # TODO: scan /usr/local/lib/pythonX.X/dist-packages for packages return """ # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # maybe: run default command if not parsedArgs.programArgs: defaultTask = self.__tasks.get("default") if defaultTask: self.run( "default", max(verbosityLevel, parsedArgs.optionData["verbosityLevel1"], parsedArgs.optionData["verbosityLevel2"])) return ap.showHelp() return # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # now: run commands specified for taskName in parsedArgs.programArgs: self.run( taskName, max(verbosityLevel, parsedArgs.optionData["verbosityLevel1"], parsedArgs.optionData["verbosityLevel2"]))
import os import typing import sys import jk_typing #import jk_prettyprintobj import jk_argparsing import jk_argparsing.textmodel import jk_logging import pypine import pypine.pypinectrl_cli ap = jk_argparsing.ArgsParser( os.path.basename(__file__), "This is the PyPine management tool. It supports installing and managing PyPine scripts." ) # --- ap.optionDataDefaults.set("help", False) # --- ap.createSynopsis("pypinectrl.py <command>") ap.createOption("h", "help", "Display this help text.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("help", True) ap.createCommand("help", "Displays this help text.")
parsedArgs.optionData.set(opt.longOption, True) # def onOptionAllRPi(argOption, argOptionArguments, parsedArgs): for opt in ALL_SYSINFO_OPTIONS: if opt.longOption in []: continue parsedArgs.optionData.set(opt.longOption, True) # ap = jk_argparsing.ArgsParser(os.path.basename(__file__), "Display system information.") ap.optionDataDefaults.set("help", False) ap.optionDataDefaults.set("color", True) ap.createOption('h', 'help', "Display this help text.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("help", True) ap.createOption(None, 'no-color', "Dont' use colors in output.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("colors", False) for opt in ALL_SYSINFO_OPTIONS: opt.register(ap) ap.createOption(None, 'i-all', "Use all system information modules (with autodetect)." ).onOption = onOptionAllAutoDetect
if cmd.endswith(":"): cmd = cmd[:-1] if cmd: processNames.append(cmd) currentPID = allProcesses[currentPID].get("ppid") if not currentPID: break return processNames # ap = jk_argparsing.ArgsParser( os.path.basename(__file__), "Checks if a specified program is a parent of the current process.") ap.optionDataDefaults.set("help", False) ap.optionDataDefaults.set("list", False) ap.optionDataDefaults.set("check", None) ap.createOption("h", "help", "Display this help text.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("help", True) ap.createOption("l", "list", "List all parent process names.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("list", True) ap.createOption("c", "check", "Check if the specified process name is part of the parent process names.").expectString("cmd", minLength=1).onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("check", argOptionArguments[0])
import os import sys import re import jk_argparsing import jk_pwdgen ap = jk_argparsing.ArgsParser("pwdgen [options]", "Generate strong passwords.") ap.optionDataDefaults.set("help", False) ap.optionDataDefaults.set("n", 1) ap.optionDataDefaults.set("length", 24) ap.optionDataDefaults.set("minNumberOfNumericChars", 2) ap.optionDataDefaults.set("numberOfSpecialChars", 3) ap.optionDataDefaults.set("prohibitedChars", "0l") ap.createOption("h", "help", "Display this help text.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("help", True) ap.createOption("n", None, "Number of passwords to generate. (Default: 1)").expectInt32("n", minValue=1).onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("n", argOptionArguments[0])
import jk_argparsing import jk_json import jk_mediawiki import jk_logging import jk_typing import jk_console import jk_mounting import jk_sysinfo from jk_mediawiki.MWManagementCtx import MWManagementCtx from jk_mediawiki.impl.AbstractProcessFilter import AbstractProcessFilter # initialize argument parser ap = jk_argparsing.ArgsParser("wikilocalctrl [options] <command>", "Manage local Wiki installations.") ap.createAuthor("Jürgen Knauth", "*****@*****.**") ap.setLicense("apache") # set defaults ap.optionDataDefaults.set("bShowHelp", False) ap.optionDataDefaults.set("bVerbose", False) ap.optionDataDefaults.set("bShowVersion", False) ap.optionDataDefaults.set("wwwWikiRootDir", None) ap.optionDataDefaults.set("httpBinDir", None) # arguments ap.createOption('h', 'help', "Display this help text and then exit.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: parsedArgs.optionData.set("bShowHelp", True)
#!/usr/bin/python3 import json import os import sys import re import jk_console import jk_sysinfo import jk_json import jk_flexdata import jk_logging from jk_typing import * import jk_argparsing ap = jk_argparsing.ArgsParser("jsonPrettyPrint", "Format JSON data.") ap.optionDataDefaults.set("help", False) ap.optionDataDefaults.set("color", True) ap.optionDataDefaults.set("stdin", False) ap.optionDataDefaults.set("extractionPath", None) ap.createOption('h', 'help', "Display this help text.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("help", True) ap.createOption(None, 'no-color', "Dont' use colors in output.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("colors", False) ap.createOption(None, 'stdin', "Read JSON data from stdin.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("stdin", True)
#!/usr/bin/python3 import warnings import sys import typing import trio import jk_console import jk_json import jk_argparsing import jk_trioping warnings.filterwarnings("ignore") ap = jk_argparsing.ArgsParser("multiping", "Ping multiple hosts at the same time.") ap.optionDataDefaults.set("help", False) ap.optionDataDefaults.set("output-format", "text") #ap.optionDataDefaults.set("color", True) ap.createOption("h", "help", "Display this help text.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("help", True) ap.createOption("j", "json", "Print output in JSON format.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("output-format", "json") ap.createAuthor("Jürgen Knauth", "*****@*****.**") ap.setLicense("Apache", YEAR=2020, COPYRIGHTHOLDER="Jürgen Knauth")
#!/usr/bin/python3 import json import os import sys import re import jk_exceptionhelper import jk_console import jk_json import jk_flexdata import jk_logging from jk_typing import * import jk_argparsing ap = jk_argparsing.ArgsParser("jkjson", "Simple JSON processor.") ap.optionDataDefaults.set("help", False) ap.optionDataDefaults.set("stdin", False) ap.optionDataDefaults.set("extractionPath", None) ap.createOption('h', 'help', "Display this help text.").onOption = \ lambda argOption, argOptionArguments, parsedArgs: \ parsedArgs.optionData.set("help", True) ap.createAuthor("Jürgen Knauth", "*****@*****.**") ap.setLicense("Apache", YEAR=2020, COPYRIGHTHOLDER="Jürgen Knauth") ap.createReturnCode(0, "Everything is okay.") ap.createReturnCode(1, "An error occurred.")