Exemplo n.º 1
0
 def test_single_key(self):
     ap = ArgumentParser()
     ap.add_argument('-f', '--foo')
     fact = ConfigFactory()
     fact.add_source(ArgumentSource(ap, ["--foo", "bar"]))
     conf = fact.build()
     self.assertEqual("bar", conf.get("foo"))
Exemplo n.º 2
0
def main():
    print("Execute as:\n $ python from_args.py --key value\n")
    ap = ArgumentParser(description="Sample from arguments")
    ap.add_argument("--key")
    fact = ConfigFactory()
    fact.add_source(ArgumentSource(ap))
    conf = fact.build()
    print("key is", conf.get("key"))
Exemplo n.º 3
0
def main():
    ap = ArgumentParser()
    ap.add_argument("--config")
    ap.add_argument("--name", default="world")
    fact = ConfigFactory()
    fact.add_source(ArgumentSource(ap))
    fact.add_source(DelegateSource(add_sources))
    conf = fact.build()
    print(f"{conf.get('greeting')}, {conf.get('name')}!")
Exemplo n.º 4
0
 def test_many_nested_keys(self):
     ap = ArgumentParser()
     ap.add_argument('--foo:bar')
     ap.add_argument('--bar')
     ap.add_argument('--foo:baz')
     fact = ConfigFactory()
     fact.add_source(
         ArgumentSource(ap,
                        ["--foo:bar", "a", "--bar", "b", "--foo:baz", "c"]))
     conf = fact.build()
     self.assertEqual("a", conf.get("foo:bar"))
     self.assertEqual("b", conf.get("bar"))
     self.assertEqual("c", conf.get("foo:baz"))
Exemplo n.º 5
0
def main():

    print("Try running a few different ways.")
    print(" 1. Run without arguments")
    print(" 2. Add key1 under app in ./config1.yaml")
    print(" 2. Run with environment SAMPLE_app_key2 set with a value.")
    print(" 3. Run with commandline: --app:key2 'humans'")

    defaults = {"app": {"key1": "Hello", "key2": "World"}}

    ap = ArgumentParser(description="Full Example")
    ap.add_argument("--app:key1")
    ap.add_argument("--app:key2")

    fact = ConfigFactory()
    fact.add_source(InMemorySource(defaults))
    fact.add_source(EnvironmentSource("SAMPLE"))
    fact.add_source(YamlSource("./config1.yaml", False))
    fact.add_source(ArgumentSource(ap))

    conf = fact.build()
    print(f"{conf.get('app:key1')}, {conf.get('app:key2')}!")