Example #1
0
def test_envelop_environment_from_file(_io):
    # Given that I load variables to my environment from a file
    _io.open.return_value = io.StringIO('FAVORITE_SUPER_HERO: Batman!')
    env = Environment.from_file('myfile.cfg')

    # When I try to find a variable defined in that file, then I see that it
    # works
    assert env.get('FAVORITE_SUPER_HERO') == 'Batman!'
Example #2
0
def test_envelop_environment_from_file():
    # Given that I load variables to my environment from a file
    env = Environment.from_file(
        os.path.join(os.path.dirname(__file__), './fixtures/env.cfg'))

    # When I try to find a variable defined in that file, then I see that it
    # works
    assert env.get('FAVORITE_SUPER_HERO') == 'Batman NANANANANA'
Example #3
0
def main():
    parser = argparse.ArgumentParser(description='Manage your environment.')
    parser.add_argument('-f',
                        '--file',
                        metavar='<FILE>',
                        type=str,
                        action='store',
                        help='File to load variables from')
    parser.add_argument(
        '-d',
        '--directory',
        metavar='<DIR>',
        type=str,
        action='store',
        help='Directory to load variables from, works just like `envparse\'')

    subparsers = parser.add_subparsers(title='subcommands', metavar='COMMAND')
    get_parser = subparsers.add_parser(
        'get', help='Get and print out the value of the variable <VAR>')
    get_parser.add_argument('cmd_get')

    get_uri_parser = subparsers.add_parser('get-uri',
                                           help='Exposes the URI parser API')
    get_uri_parser.add_argument('cmd_get_uri', nargs=2)

    args = parser.parse_args()

    if args.file:
        env = Environment.from_file(args.file)
    if args.directory:
        env = Environment.from_folder(args.directory)

    if hasattr(args, 'cmd_get'):
        return env.get(args.cmd_get)

    if hasattr(args, 'cmd_get_uri'):
        part, variable = args.cmd_get_uri
        return getattr(env.get_uri(variable), part)