Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

enum-actions

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enum-actions

For easy selection command-line selection of an `enum.Enum` variant with `argparse.Action`s.

  • 0.1.2
  • PyPI
  • Socket score

Maintainers
1

pypi github

enum-actions

For easy selection command-line selection of an enum.Enum variant with argparse.Actions.

Use it like this:

>>> from enum_actions import enum_action
>>> from argparse import ArgumentParser
>>> import enum

>>> class MyEnum(enum.Enum):
...     A = 1
...     B = 2

>>> parser = ArgumentParser()
>>> _ = parser.add_argument("-e", "--enum", action=enum_action(MyEnum), default="a", help="pick a variant") # create an action for your enum
>>> args = parser.parse_args() # there will be an instance of MyEnum in the args object

Features

Choices are handled transparently

foo.py --help

usage: foo.py [-h] [-e {a,b}]

optional arguments:
  -h, --help            show this help message and exit
  -e {a,b}, --enum {a,b}
                        pick a variant (default: b)

Defaults are handled transparently

Having a default string or enum will both work

parser.add_argument("--enum", action=enum_action(MyEnum), default="a")
parser.add_argument("--enum", action=enum_action(MyEnum), default=MyEnum.A)

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc