{"id":15360601,"url":"https://github.com/tkf/traitscli","last_synced_at":"2026-01-19T05:33:32.233Z","repository":{"id":4739229,"uuid":"5888529","full_name":"tkf/traitscli","owner":"tkf","description":"CLI generator for Python based on class traits","archived":false,"fork":false,"pushed_at":"2013-03-22T20:11:30.000Z","size":220,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-13T20:48:02.519Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tkf.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-09-20T15:17:45.000Z","updated_at":"2015-04-06T14:45:34.000Z","dependencies_parsed_at":"2022-09-18T11:41:24.092Z","dependency_job_id":null,"html_url":"https://github.com/tkf/traitscli","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkf%2Ftraitscli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkf%2Ftraitscli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkf%2Ftraitscli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkf%2Ftraitscli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tkf","download_url":"https://codeload.github.com/tkf/traitscli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247492549,"owners_count":20947545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T12:50:55.395Z","updated_at":"2026-01-19T05:33:32.206Z","avatar_url":"https://github.com/tkf.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Traits CLI - CLI generator based on class traits\n================================================\n\nTraits CLI is based on Enthought's Traits_ library.\n\nSome benefits:\n\n* Automatically set type (int/float/...) of command line argument.\n* Help string generation.\n* \"Deep value\"\" configuration:\n  e.g., ``--dict['a']['b']['c']=1`` is equivalent to\n  ``obj.dict['a']['b']['c'] = 1`` in Python code.\n* Nested class configuration:\n  e.g., ``--sub.attr=val`` is equivalent to\n  ``obj.sub.attr = val`` in Python code.\n* Parameter file support (ini/conf, json, yaml, etc.).\n  Load parameter from file then set attribute.\n\n.. _traits: https://github.com/enthought/traits\n\n\nLinks\n-----\n\n* `Documentaions (at Read the Docs) \u003chttp://traits-cli.readthedocs.org/\u003e`_\n* `Source code repository (at GitHub) \u003chttps://github.com/tkf/traitscli\u003e`_\n* `Issue tracker (at GitHub) \u003chttps://github.com/tkf/traitscli/issues\u003e`_\n* `PyPI \u003chttp://pypi.python.org/pypi/traitscli\u003e`_\n* `Travis CI \u003chttps://travis-ci.org/#!/tkf/traitscli\u003e`_\n\n\nInstallation\n------------\n::\n\n  pip install traitscli\n\n\nDependencies\n------------\n\n- traits_\n- argparse (for Python \u003c 2.7)\n\n\nSample\n------\n\n.. [[[cog import _cogutils as _; _.inject_sample_doc() ]]]\n\nSource code::\n\n  from traitscli import TraitsCLIBase\n  from traits.api import Bool, Float, Int, Str, Enum\n\n\n  class SampleCLI(TraitsCLIBase):\n\n      '''\n      Sample CLI using `traitscli`.\n\n      Example::\n\n        %(prog)s --yes                # =\u003e obj.yes = True\n        %(prog)s --string something   # =\u003e obj.string = 'string'\n        %(prog)s --choice x           # =\u003e raise error (x is not in {a, b, c})\n\n      '''\n\n      # These variables are configurable by command line option\n      yes = Bool(desc='yes flag for sample CLI', config=True)\n      no = Bool(True, config=True)\n      fnum = Float(config=True)\n      inum = Int(config=True)\n      string = Str(config=True)\n      choice = Enum(['a', 'b', 'c'], config=True)\n\n      # You can have \"internal\" attributes which cannot be set via CLI.\n      not_configurable_from_cli = Bool()\n\n      def do_run(self):\n          names = self.class_trait_names(config=True)\n          width = max(map(len, names))\n          for na in names:\n              print \"{0:{1}} : {2!r}\".format(na, width, getattr(self, na))\n\n\n  if __name__ == '__main__':\n      # Run command line interface\n      SampleCLI.cli()\n\n\nExample run::\n\n  $ python sample.py --help\n  usage: sample.py [-h] [--choice {a,b,c}] [--fnum FNUM] [--inum INUM] [--no]\n                   [--string STRING] [--yes]\n\n  Sample CLI using `traitscli`.\n\n  Example::\n\n    sample.py --yes                # =\u003e obj.yes = True\n    sample.py --string something   # =\u003e obj.string = 'string'\n    sample.py --choice x           # =\u003e raise error (x is not in {a, b, c})\n\n  optional arguments:\n    -h, --help        show this help message and exit\n    --choice {a,b,c}  (default: a)\n    --fnum FNUM       (default: 0.0)\n    --inum INUM       (default: 0)\n    --no              (default: True)\n    --string STRING   (default: )\n    --yes             yes flag for sample CLI (default: False)\n\n  $ python sample.py --yes --choice a\n  string : ''\n  no     : True\n  fnum   : 0.0\n  choice : 'a'\n  inum   : 0\n  yes    : True\n\n  $ python sample.py --inum invalid_argument\n  usage: sample.py [-h] [--choice {a,b,c}] [--fnum FNUM] [--inum INUM] [--no]\n                   [--string STRING] [--yes]\n  sample.py: error: argument --inum: invalid int value: 'invalid_argument'\n\n.. [[[end]]]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkf%2Ftraitscli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftkf%2Ftraitscli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkf%2Ftraitscli/lists"}