{"id":19665242,"url":"https://github.com/alttch/icli","last_synced_at":"2025-04-28T22:31:05.126Z","repository":{"id":62570204,"uuid":"211575537","full_name":"alttch/icli","owner":"alttch","description":"interactive command line interfaces for Python","archived":false,"fork":false,"pushed_at":"2021-01-03T22:39:53.000Z","size":70,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T11:05:12.182Z","etag":null,"topics":["auto-completion","cli","cli-interface","command-line","interactive","python","python3","user-interface"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alttch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-28T23:53:49.000Z","updated_at":"2024-12-23T13:34:26.000Z","dependencies_parsed_at":"2022-11-03T21:17:18.058Z","dependency_job_id":null,"html_url":"https://github.com/alttch/icli","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Ficli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Ficli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Ficli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Ficli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alttch","download_url":"https://codeload.github.com/alttch/icli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251397577,"owners_count":21583034,"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":["auto-completion","cli","cli-interface","command-line","interactive","python","python3","user-interface"],"created_at":"2024-11-11T16:21:46.104Z","updated_at":"2025-04-28T22:31:04.739Z","avatar_url":"https://github.com/alttch.png","language":"Python","readme":"# icli - interactive command line interfaces\n\n## What is icli\n\n**icli** is a Python library, built on top of **argparse**, which allows you to\nquickly build rich interactive command line interfaces with sections, command\nhistory, command batch processing, command repeating and interactive\nauto-complete.\n\n\u003cimg src=\"https://github.com/alttch/icli/blob/master/demo.gif?raw=true\" width=\"800\" /\u003e\n\n**icli** uses **readline** library for command inputs.\n\n## Features\n\n* Jump between command sections (use / for root section, .. or Ctrl-d to jump\n  to upper section)\n\n* Send multiple commands, separated with *;*\n\n* Repeat command execution, by adding *|X* to the end of input (X - delay in\n  seconds between commands, use *|cX* to clear screen before next command\n  execution)\n\n* Auto-completion (via **argcomplete**)\n\n## How to install\n\n```\npip3 install icli\n```\n\n## How to use\n\n* use **icli.ArgumentParser** just like **argparse.ArgumentParser** (create\n  parsers, sub-parsers etc.)\n\n* create dispatcher method for commands. This method receives parsed arguments\n  in \\*\\*kwargs:\n\n```python\n\ndef dispatcher(**kwargs):\n    # ....\n```\n\n* define CLI sections tree and start interactive mode:\n\n```python\nimport icli\nap = icli.ArgumentParser()\n\n# ...\n\nap.sections = {'user': ['account', 'apikey'], 'document': []}\nap.run = dispatcher\nap.interactive()\n```\n\n## Customizing\n\nOverride:\n\n* **get_interactive_prompt** customize input prompt\n* **print_repeat_title** customize title for repeating commands\n* **handle_interactive_exception** handle exceptions, raised during interactive\n  loop\n\n## Global commands\n\nYou may define global commands, which work in all sections, e.g. let's make *w*\nsystem command executed, when user type *w*:\n\n```python\ndef w(*args):\n    # the method receives command name and optional command arguments in *args\n    import os\n    os.system('w')\n\nap.interactive_global_commands['w'] = w\n```\n\nNote: global commands are not auto-completed\n\n## History file\n\nIf history file is defined, input commands are loaded before interactive\nsession is started and saved at the end.\n\n```python\nap.interactive_history_file = '~/.test-icli'\n```\n\nBy default, last 100 commands are saved. To change this behavior, modify:\n\n```python\nap.interactive_history_length = 500\n```\n\n## Combining shell and interactive CLI\n\nLet's launch interactive mode when your program is started without arguments,\notherwise process them:\n\n```python\nimport sys\n\n# prog param sets program name in help to empty for interactive mode\nap = icli.ArgumentParser(prog='' if len(sys.argv) \u003c 2 else None)\n\n# ...\n\nif len(sys.argv) \u003e 1:\n    ap.launch()\nelse:\n    ap.interactive()\n```\n\n## Batch processing\n\nYour program may read commands from stdin or external file, then process them\nwithout user input\n\nTo do this, put commands to I/O steam and launch **batch** method:\n\n```python\nimport io\n\nf = io.StringIO()\nf.write('user account list ; user apikey list\\ndocument list')\nf.seek(0)\nap.batch(f)\n```\n\nor just launch **batch** method with a source stream:\n\n```python\nwith open('commands.list') as cf:\n    ap.batch(cf)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falttch%2Ficli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falttch%2Ficli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falttch%2Ficli/lists"}