# Custom Argparse Arguments

The `dataclasses.field()` function is used to customize the declaration of
fields on a dataclass. It accepts, among others, the `default`,
`default_factory`, arguments used to set the default instance values to fields
(please take a look at the [official documentation](https://docs.python.org/3/library/dataclasses.html#dataclasses.field) For more
information).

`simple-parsing` provides an overloaded version of this function:
`simple_parsing.field()`, which, in addition to all the above-mentioned keyword
arguments of the `field()` method, **can be passed any of the arguments
of the usual `add_argument(*option_strings, **kwargs)` function!**.

The values passed this way take precedence over those auto-generated by
`simple-parsing`, allowing you to do pretty much anything you want.

## Examples

- ### List of choices

  For example, here is how you would create a list of choices, whereby any
  of the passed arguments can only be contained within the choices:

  ```python

  from dataclasses import dataclass
  from simple_parsing import ArgumentParser, field
  from typing import List

  @dataclass
  class Foo:
      """ Some class Foo """

      # A sequence of tasks.
      task_sequence: List[str] = field(choices=["train", "test", "ood"])

  parser = ArgumentParser()
  parser.add_arguments(Foo, "foo")

  args = parser.parse_args("--task_sequence train train ood".split())
  foo: Foo = args.foo
  print(foo)
  assert foo.task_sequence == ["train", "train", "ood"]

  ```

- ### Adding additional aliases for an argument

  By passing the

  ```python
  @dataclass
  class Foo(TestSetup):
      """ Some example Foo. """
      # The output directory. (can be passed using any of "-o" or --out or )
      output_dir: str = field(
          default="/out",
          alias=["-o", "--out"],
          choices=["/out", "/bob"]
      )

  foo = Foo.setup("--output_dir /bob")
  assert foo.output_dir == "/bob"

  with raises():
      foo = Foo.setup("-o /cat")
      assert foo.output_dir == "/cat"

  foo = Foo.setup("--out /bob")
  assert foo.output_dir == "/bob"
  ```

- ### Adding Flags with "store-true" or "store-false"

  Additionally,
