"-s/ ", help="Short mode, print only ids (implies -q and -nc)", default=False) @click.option("--no-color/--color", "-nc/ ", help="No color in terminal output", default=False) @click.pass_context def cli(ctx, quiet, short, no_color): """ Dirty Incident Response Toolkit\n psrok1 @ 2017-2019 """ log.QUIET_MODE = quiet or short log.SHORT_MODE = short log.NO_COLOR = no_color or short pass # Import all submodules extensions.register_subcommands( cli, [commands] + extensions.get_submodule_plugins("commands"), "COMMAND") def main(): cli(obj={}) if __name__ == "__main__": main()
import click from dirt.libs import extensions, incident, log import sys current_module = sys.modules[__name__] @click.group("vcs", help="Incident version control") @click.option("--incident_id", "-i", default="current") @click.pass_context def vcs_command(ctx, incident_id): """ Here we're adding new command to dirt - vcs """ current = incident.choose_incident(incident_id) if current is None: log.error("No incident found.") ctx.abort() ctx.obj["INCIDENT"] = current # Our new command has also some subcommands extensions.register_subcommands(vcs_command, [current_module], "SUBCOMMAND") COMMAND = vcs_command
return custom_attribute_handler @click.group("del", help="Remove attribute (indicator) from incident", cls=extensions.extendable_group(custom_attribute)) @click.option("--incident_id", "-i", default="current", autocompletion=complete.get_completer(complete.incident_list)) @click.option("--force", "-f", is_flag=True, default=False) @click.pass_context @hooks.hookable def del_command(ctx, incident_id, force): current = incident.choose_incident(incident_id) if current is None: log.error("No incident found.") ctx.abort() if current.closed and not force: log.error("Incident is closed - you must open it before adding items.") ctx.abort() ctx.obj["INCIDENT"] = current extensions.register_subcommands(del_command, [attributes] + extensions.get_submodule_plugins("attributes"), "DEL_COMMAND") COMMAND = del_command
context_settings=dict( ignore_unknown_options=True) ) @click.argument("args", nargs=-1, type=click.UNPROCESSED, autocompletion=command_arg_completer) def custom_shell_command(args): try: args = [quote(incident.expand_incident_arg(arg)) for arg in args] except RuntimeError as e: log.error(str(e)) ctx.abort() return log.shell(name+' '+(' '.join(args))) return custom_shell_command @click.group("shell", cls=extensions.extendable_group(custom_command), hidden=True) @click.pass_context @hooks.hookable def shell_command(ctx): log.NO_COLOR = True pass extensions.register_subcommands(shell_command, [shcmd] + extensions.get_submodule_plugins("shcmd"), "COMMAND") COMMAND = shell_command