コード例 #1
0
ファイル: gencomp.py プロジェクト: mzdaniel/python-clg
def main():
    cmd = clg.CommandLine(CMD)
    global args
    args = cmd.parse()
    global shell
    shell = args.command0

    if args.format == 'yaml':
        import yaml
        config = yaml.load(open(args.conf_file),
                           Loader=clg.YAMLOrderedDictLoader)
    elif args.format == 'json':
        import simplejson as json
        config = json.loads(open('command.json'),
                            object_pairs_hook=OrderedDict)

    functions = '\n'.join(
        parse_config(shell, '_%s' % args.prog, config, [],
                     args.ignore_options))
    script = {
        'bash':
        lambda: BASH_SCRIPT.format(prog=args.prog, functions=functions),
        'zsh':
        lambda: ZSH_SCRIPT.format(prog=args.prog,
                                  functions=functions,
                                  command=SIMPLE_COMMAND
                                  if args.simple else MENU_COMMAND,
                                  ext='' if args.simple else '_desc')
    }[shell]()

    with open(args.output_file, 'w') as fhandler:
        fhandler.write(script)
コード例 #2
0
def parse_args(app_settings_dir, args=None):
    """
    Looks for all the specs for specified app
    and parses the commandline input arguments accordingly.

    Trim clg spec from customized input and modify help data.

    :param app_settings_dir: path to the base directory holding the
        application's settings. App can be provisioner\installer\tester
        and the path would be: settings/<app_name>/
    :param args: the list of arguments used for directing the method to work
        on something other than CLI input (for example, in testing).
    :return: dict. Based on cmd-line args parsed from spec file
    """
    # Dict with the merging result of all app's specs
    app_specs = _get_specs(app_settings_dir)

    # Get the subparsers options as is with all the fields from app's specs.
    # This also trims some custom fields from options to pass to clg.
    subparsers_options = _get_subparsers_options(app_specs)

    # Pass trimmed spec to clg with modified help message
    cmd = clg.CommandLine(app_specs)
    clg_args = vars(cmd.parse(args))
    ValueArgument.init_missing_args(app_specs, clg_args, app_settings_dir,
                                    subcommand=clg_args["command0"])

    # Current sub-parser options
    sub_parser_options = subparsers_options.get(clg_args['command0'], {})

    override_default_values(clg_args, sub_parser_options)
    return clg_args
コード例 #3
0
ファイル: lib.py プロジェクト: ebenolson/loadconfig
def _clg_parse(clg_key, args, types):
    '''Parse cli arguments using clg key.
    types: optional list of custom functions for argument checking.
    clg_key.default_cmd: optional command if none is passed on the cli args.
    '''
    if 'default_cmd' in clg_key:
        default_cmd = clg_key['default_cmd']
        del clg_key['default_cmd']
    with _patch_argparse_clg(args, types), exc(SystemExit) as e:
        clg_args = clg.CommandLine(deepcopy(clg_key)).parse(args[1:])
    if e() and hasattr(e(), 'code') and e().code.startswith('usage:') and \
     'default_cmd' in locals() and '-h' not in args and '--help' not in args:
        # Try clg parsing once more with default_cmd
        new_args = [default_cmd] + args[1:]
        with _patch_argparse_clg(args, types), exc(SystemExit) as e:
            clg_args = clg.CommandLine(deepcopy(clg_key)).parse(new_args)
        if e():
            raise e()
    elif e():
        raise e()
    return clg_args
コード例 #4
0
ファイル: simple.py プロジェクト: mzdaniel/python-clg
def main():
    cmd_conf = json.load(open('simple.json'), object_pairs_hook=OrderedDict)
    #    cmd_conf = yaml.load(open('simple.yml'), Loader=yamlordereddictloader.Loader)
    cmd = clg.CommandLine(cmd_conf)
    args = cmd.parse()
    print("Print Namespace object: %s" % args)
    print("Print Namespace attributes: %s" % vars(args))
    print("Iter arguments:")
    for arg, value in args:
        print("  %s: %s" % (arg, value))
    print("Access 'foo' option with attribute syntax: %s" % args.foo)
    print("Access 'foo' option with list syntax: %s" % args['foo'])
コード例 #5
0
def main():
    cmd = clg.CommandLine(yaml.load(open('groups.yml')))
    print(cmd.parse())
コード例 #6
0
ファイル: subparsers.py プロジェクト: mzdaniel/python-clg
def main():
    cmd = clg.CommandLine(
        yaml.load(open('subparsers.yml'), Loader=yamlordereddictloader.Loader))
    print(cmd.parse())
コード例 #7
0
ファイル: main.py プロジェクト: Toure/InfraRed-Core
def main():
    cmd = clg.CommandLine(COMBINED_CONF)
    return cmd.parse()
コード例 #8
0
import clg
import yaml

cmd = clg.CommandLine(yaml.load(open('builtins.yml')))
args = cmd.parse()
print(args.sum(args.integers))
コード例 #9
0
from faker import Faker
import csv
import clg
import datetime
import random
import yaml
import yamlordereddictloader

fake = Faker()

cmd = clg.CommandLine(yaml.load(open('src/claims.yaml'), Loader=yamlordereddictloader.Loader))
args = cmd.parse()

lifecycles = ["New", "Assigned", "Hold",
              "Violation", "Pending", "Resolved", "Audit"]
csrs = ["csr1", "csr2", "csr3", "csr4", "csr5"]
priorities = ["Low", "Routine", "High"]
origins = ["Member", "Provider"]
claimTypes = ["Provider", "Clinic", "Hospital", "ER", "Ambulatory"]
queues = ["claim-queue-1", "claim-queue-2",
          "claim-queue-3", "claim-queue-4", "claim-queue-5"]

header = '"name","type","dc:title","ecm:currentLifeCycleState","dc:source"'
header += ',"claim:priority","claim:type","claim:origin","claim:queue","claim:totalCharge"'
header += ',"claim:assignedUser","claim:sccf","claim:messageID","claim:submitter"'
header += ',"dc:created","claim:serviceDate","claim:received","claim:holdDate"'
header += ',"dc:modified","claim:providerID","claim:memberID"'
header += ',"dc:creator","dc:contributors","dc:lastContributor"'

template = '"%s","Claim","%s","%s","Upload"'
template += ',"%s","%s","%s","%s","%s"'
コード例 #10
0
ファイル: kvm.py プロジェクト: mzdaniel/python-clg
def main():
    cmd = clg.CommandLine(
        yaml.load(open('kvm.yml'), Loader=yamlordereddictloader.Loader))
    cmd.parse()