{"id":21816624,"url":"https://github.com/5monkeys/cmd2","last_synced_at":"2025-08-23T05:34:32.904Z","repository":{"id":4736421,"uuid":"5885476","full_name":"5monkeys/cmd2","owner":"5monkeys","description":"A fork of the Python cmd2 module.","archived":false,"fork":false,"pushed_at":"2012-03-05T21:49:13.000Z","size":1782,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-21T10:13:27.247Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/5monkeys.png","metadata":{"files":{"readme":"README.txt","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-09-20T11:28:16.000Z","updated_at":"2016-10-18T11:57:13.000Z","dependencies_parsed_at":"2022-08-19T11:53:49.483Z","dependency_job_id":null,"html_url":"https://github.com/5monkeys/cmd2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/5monkeys/cmd2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5monkeys%2Fcmd2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5monkeys%2Fcmd2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5monkeys%2Fcmd2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5monkeys%2Fcmd2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/5monkeys","download_url":"https://codeload.github.com/5monkeys/cmd2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5monkeys%2Fcmd2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271745595,"owners_count":24813509,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-27T15:35:36.801Z","updated_at":"2025-08-23T05:34:32.872Z","avatar_url":"https://github.com/5monkeys.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"----\r\ncmd2\r\n----\r\n\r\n:Author: Catherine Devlin, http://catherinedevlin.blogspot.com\r\n\r\n`cmd2` is a tool for writing command-line interactive applications.  It is based on the Python Standard Library's `cmd` module, and can be used anyplace `cmd` is used simply by importing `cmd2` instead.\r\n\r\n`cmd2` provides the following features, in addition to those already existing in `cmd`:\r\n\r\n- Searchable command history\r\n- Load commands from file, save to file, edit commands in file\r\n- Multi-line commands\r\n- Case-insensitive commands\r\n- Special-character shortcut commands (beyond cmd's `@` and `!`)\r\n- Settable environment parameters\r\n- Parsing commands with flags\r\n- Redirection to file with `\u003e`, `\u003e\u003e`; input from file with `\u003c`\r\n- Bare '\u003e', '\u003e\u003e' with no filename send output to paste buffer\r\n- Pipe output to shell commands with `|`\r\n- Simple transcript-based application testing\r\n\r\nInstructions for implementing each feature follow.\r\n\r\n- Searchable command history\r\n\r\n    All commands will automatically be tracked in the session's history, unless the command is listed in Cmd's excludeFromHistory attribute.  \r\n    The history is accessed through the `history`, `list`, and `run` commands \r\n    (and their abbreviations: `hi`, `li`, `l`, `r`).\r\n    If you wish to exclude some of your custom commands from the history, append their names\r\n    to the list at Cmd.ExcludeFromHistory.\r\n\r\n- Load commands from file, save to file, edit commands in file\r\n\r\n    Type `help load`, `help save`, `help edit` for details.\r\n  \r\n- Multi-line commands\r\n\r\n    Any command accepts multi-line input when its name is listed in `Cmd.multilineCommands`.\r\n    The program will keep expecting input until a line ends with any of the characters \r\n    in `Cmd.terminators` .  The default terminators are `;` and `/n` (empty newline).\r\n    \r\n- Case-insensitive commands\r\n\r\n    All commands are case-insensitive, unless `Cmd.caseInsensitive` is set to `False`.\r\n  \r\n- Special-character shortcut commands (beyond cmd's \"@\" and \"!\")\r\n\r\n    To create a single-character shortcut for a command, update `Cmd.shortcuts`.\r\n  \r\n- Settable environment parameters\r\n\r\n    To allow a user to change an environment parameter during program execution, \r\n    append the parameter's name to `Cmd.settable`.\r\n    \r\n- Parsing commands with `optparse` options (flags) \r\n\r\n    ::\r\n    \r\n        @options([make_option('-m', '--myoption', action=\"store_true\", help=\"all about my option\")])\r\n        def do_myfunc(self, arg, opts):\r\n            if opts.myoption:\r\n                ...\r\n            \r\n    See Python standard library's `optparse` documentation: http://docs.python.org/lib/optparse-defining-options.html\r\n    \r\ncmd2 can be installed with `easy_install cmd2`\r\n\r\nCheese Shop page: http://pypi.python.org/pypi/cmd2\r\n\r\nExample cmd2 application (example/example.py) ::\r\n\r\n    '''A sample application for cmd2.'''\r\n    \r\n    from cmd2 import Cmd, make_option, options, Cmd2TestCase\r\n    import unittest, optparse, sys\r\n    \r\n    class CmdLineApp(Cmd):\r\n        multilineCommands = ['orate']\r\n        Cmd.shortcuts.update({'\u0026': 'speak'})\r\n        maxrepeats = 3\r\n        Cmd.settable.append('maxrepeats')\r\n    \r\n        @options([make_option('-p', '--piglatin', action=\"store_true\", help=\"atinLay\"),\r\n                  make_option('-s', '--shout', action=\"store_true\", help=\"N00B EMULATION MODE\"),\r\n                  make_option('-r', '--repeat', type=\"int\", help=\"output [n] times\")\r\n                 ])\r\n        def do_speak(self, arg, opts=None):\r\n            \"\"\"Repeats what you tell me to.\"\"\"\r\n            arg = ''.join(arg)\r\n            if opts.piglatin:\r\n                arg = '%s%say' % (arg[1:], arg[0])\r\n            if opts.shout:\r\n                arg = arg.upper()\r\n            repetitions = opts.repeat or 1\r\n            for i in range(min(repetitions, self.maxrepeats)):\r\n                self.stdout.write(arg)\r\n                self.stdout.write('\\n')\r\n                # self.stdout.write is better than \"print\", because Cmd can be\r\n                # initialized with a non-standard output destination\r\n    \r\n        do_say = do_speak     # now \"say\" is a synonym for \"speak\"\r\n        do_orate = do_speak   # another synonym, but this one takes multi-line input\r\n    \r\n    class TestMyAppCase(Cmd2TestCase):\r\n        CmdApp = CmdLineApp\r\n        transcriptFileName = 'exampleSession.txt'\r\n    \r\n    parser = optparse.OptionParser()\r\n    parser.add_option('-t', '--test', dest='unittests', action='store_true', default=False, help='Run unit test suite')\r\n    (callopts, callargs) = parser.parse_args()\r\n    if callopts.unittests:\r\n        sys.argv = [sys.argv[0]]  # the --test argument upsets unittest.main()\r\n        unittest.main()\r\n    else:\r\n        app = CmdLineApp()\r\n        app.cmdloop()\r\n\r\nThe following is a sample session running example.py.\r\nThanks to `TestMyAppCase(Cmd2TestCase)`, it also serves as a test \r\nsuite for example.py when saved as `exampleSession.txt`.  \r\nRunning `python example.py -t` will run all the commands in the\r\ntranscript against `example.py`, verifying that the output produced\r\nmatches the transcript.\r\n\r\nexample/exampleSession.txt::\r\n\r\n    (Cmd) help\r\n    \r\n    Documented commands (type help \u003ctopic\u003e):\r\n    ========================================\r\n    _load  edit  history  li    load   pause  run   say  shell      show \r\n    ed     hi    l        list  orate  r      save  set  shortcuts  speak\r\n    \r\n    Undocumented commands:\r\n    ======================\r\n    EOF  cmdenvironment  eof  exit  help  q  quit\r\n\r\n    (Cmd) help say\r\n    Repeats what you tell me to.\r\n    Usage: speak [options] arg\r\n    \r\n    Options:\r\n      -h, --help            show this help message and exit\r\n      -p, --piglatin        atinLay\r\n      -s, --shout           N00B EMULATION MODE\r\n      -r REPEAT, --repeat=REPEAT\r\n                            output [n] times\r\n    \r\n    (Cmd) say goodnight, Gracie\r\n    goodnight, Gracie\r\n    (Cmd) say -ps --repeat=5 goodnight, Gracie\r\n    OODNIGHT, GRACIEGAY\r\n    OODNIGHT, GRACIEGAY\r\n    OODNIGHT, GRACIEGAY\r\n    (Cmd) set\r\n    prompt: (Cmd)\r\n    editor: gedit\r\n    echo: False\r\n    maxrepeats: 3\r\n    (Cmd) set maxrepeats 5\r\n    maxrepeats - was: 3\r\n    now: 5\r\n    (Cmd) say -ps --repeat=5 goodnight, Gracie\r\n    OODNIGHT, GRACIEGAY\r\n    OODNIGHT, GRACIEGAY\r\n    OODNIGHT, GRACIEGAY\r\n    OODNIGHT, GRACIEGAY\r\n    OODNIGHT, GRACIEGAY\r\n    (Cmd) hi\r\n    -------------------------[1]\r\n    help\r\n    -------------------------[2]\r\n    help say\r\n    -------------------------[3]\r\n    say goodnight, Gracie\r\n    -------------------------[4]\r\n    say -ps --repeat=5 goodnight, Gracie\r\n    -------------------------[5]\r\n    set\r\n    -------------------------[6]\r\n    set maxrepeats 5\r\n    -------------------------[7]\r\n    say -ps --repeat=5 goodnight, Gracie\r\n    (Cmd) run 4\r\n    say -ps --repeat=5 goodnight, Gracie\r\n    OODNIGHT, GRACIEGAY\r\n    OODNIGHT, GRACIEGAY\r\n    OODNIGHT, GRACIEGAY\r\n    OODNIGHT, GRACIEGAY\r\n    OODNIGHT, GRACIEGAY\r\n    (Cmd) orate Four score and\r\n    \u003e seven releases ago\r\n    \u003e our BDFL\r\n    \u003e blah blah blah\r\n    \u003e\r\n    \u003e\r\n    Four score and seven releases ago our BDFL blah blah blah\r\n    (Cmd) \u0026 look, a shortcut!\r\n    look, a shortcut!\r\n    (Cmd) say put this in a file \u003e myfile.txt\r\n    (Cmd) say \u003c myfile.txt\r\n    put this in a file\r\n    (Cmd) set prompt \"---\u003e \"\r\n    prompt - was: (Cmd)\r\n    now: ---\u003e\r\n    ---\u003e say goodbye\r\n    goodbye","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F5monkeys%2Fcmd2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F5monkeys%2Fcmd2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F5monkeys%2Fcmd2/lists"}