Skip to content

Parameter Sources

While generally, input is parsed from the command line, there are a few other sources that can be used to provide input.

The precedence of sources is:

  1. Commane Line
  2. Environment Variables
  3. Input Prompt
  4. Default Value

Type Conversion

All input sources, except for default value, will still pass through the type conversion systems that arc provides.

Environment Variables

examples/from_env.py
import arc
import os

os.environ["VAL"] = "2"


@arc.command()
def command(val: int = arc.Argument(envvar="VAL")):
    arc.print(f"VAL: {val}")


command()
Now, if the argument isn't present ont he command line, it will be parsed from the environment variable VAL
$ python from_env.py 
VAL: 2
$ python from_env.py 10
VAL: 10

Input Prompt

If there is no input provided on the command line for name (and there was no enviroment variable), arc will prompt the user for input.

examples/from_prompt.py
import arc


@arc.command()
def command(name: str = arc.Argument(prompt="What is your first name?")):
    arc.print("Hello, " + name)


command()
$ python from_prompt.py Jolyne
Hello, Jolyne

$ python from_prompt.py
What is your name? Jolyne
Hello, Jolyne
If the parameter is optional, the user will be still be prompted, but the user can enter an empty input by just pressing Enter and the default will be used.