{"id":14008135,"url":"https://github.com/aelsabbahy/dargs","last_synced_at":"2026-01-16T20:51:34.368Z","repository":{"id":57501192,"uuid":"104828639","full_name":"aelsabbahy/dargs","owner":"aelsabbahy","description":"Enhance any command with dynamic arguments","archived":false,"fork":false,"pushed_at":"2017-10-03T12:22:05.000Z","size":41,"stargazers_count":112,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-30T19:38:07.689Z","etag":null,"topics":["autocompletion","bash-completion","command-line","completions","productivity","zsh-completions"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aelsabbahy.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":"2017-09-26T02:57:48.000Z","updated_at":"2023-03-22T10:37:59.000Z","dependencies_parsed_at":"2022-09-14T19:41:47.414Z","dependency_job_id":null,"html_url":"https://github.com/aelsabbahy/dargs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/aelsabbahy/dargs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aelsabbahy%2Fdargs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aelsabbahy%2Fdargs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aelsabbahy%2Fdargs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aelsabbahy%2Fdargs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aelsabbahy","download_url":"https://codeload.github.com/aelsabbahy/dargs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aelsabbahy%2Fdargs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28482356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["autocompletion","bash-completion","command-line","completions","productivity","zsh-completions"],"created_at":"2024-08-10T11:01:16.823Z","updated_at":"2026-01-16T20:51:34.353Z","avatar_url":"https://github.com/aelsabbahy.png","language":"Go","readme":"# Dargs - Dynamic CLI arguments and completion\n[![Build Status](https://circleci.com/gh/aelsabbahy/dargs.png)](https://circleci.com/gh/aelsabbahy/dargs)\n**\n[![Twitter Follow](https://img.shields.io/twitter/follow/aelsabbahy1.svg?style=social\u0026label=Follow\u0026maxAge=2592000)]()\n[![Blog](https://img.shields.io/badge/follow-blog-brightgreen.svg)](https://medium.com/@aelsabbahy)\n\n# Introduction\n\n**Contributions Wanted:** If you have use-cases/configurations that could benefit others, please submit them to the\n[examples](examples/) folder.\n\n\u003ca href=\"https://asciinema.org/a/AwMi8FkS33bQtna7yTlvAEYwf?autoplay=1\" target=\"_blank\"\u003e\u003cimg src=\"https://user-images.githubusercontent.com/6783261/30841588-3d75422a-a24b-11e7-8108-238d805dbde6.gif\" alt=\"asciicast\"\u003e\u003c/a\u003e\n\n## What is Dargs?\n\nDargs is a tool that allows you to define dynamic argument transformations and completions for any CLI command.\n\nFeatures:\n* Use regex to define which CLI argument should be processed\n* Use any external command as an argument transformer or completer\n* Define cache duration for results\n\nFor example, using dargs one can define rules to:\n\n* ssh into an ec2 instance by instance id:\n\n  `ssh i-xxxxxxxx`\n\n* Run packer build using YAML file format instead of JSON:\n\n    `packer build demo.yml`\n\n* ssh completions for AWS ec2 instance names:\n\n    `ssh ec2:instance_name\u003ctab\u003e`\n\n\n## Installation\n\nIf you have go\n```bash\ngo get -u github.com/aelsabbahy/dargs\n```\n\nIf not, download the stand-alone binary\n\nLinux:\n```bash\ncurl -L https://github.com/aelsabbahy/dargs/releases/download/v0.0.2/dargs_linux_amd64 -o /usr/local/bin/dargs\nchmod +rx /usr/local/bin/dargs\n```\n\nOSX:\n```bash\ncurl -L https://github.com/aelsabbahy/dargs/releases/download/v0.0.2/dargs_darwin_amd64 -o /usr/local/bin/dargs\nchmod +rx /usr/local/bin/dargs\n```\n\n\n### Completions installation\n\n**Bash:**\n\nAdd the following to your `~/.bashrc`\n```bash\nif [[ \"$(ls -A ~/.dargs/completions/bash)\" ]];then\n  for f in ~/.dargs/completions/bash/*;do source \"$f\";done\nfi\n```\n**Zsh:**\n\nAdd the following to your `~/.zshrc`\n```bash\nif [[ \"$(ls -A ~/.dargs/completions/zsh)\" ]];then\n  for f in ~/.dargs/completions/zsh/*;do source \"$f\";done\nfi\n```\n\n## Tutorial\n\n**Note:** This section walks through the basics of dargs, for more detailed information, see [manual](#manual)\n\nNow that you have dargs installed, lets use dargs to enhance ssh with ec2 abilities and give packer YAML support.\n\nFirst, create the following `~/.dargs.yml` config file:\n```yaml\nimports:\n  - https://raw.githubusercontent.com/aelsabbahy/dargs/master/examples/quick_start.yml\n\ncommands:\n  - name: /usr/bin/ssh\n    wrapper: ssh\n    # Use fzf to fuzzy complete (must have fzf installed)\n    #fzf-complete: true\n    completers:\n      - ec2_name\n    transformers:\n      - ec2_name # transforms ec2:instance_name -\u003e instance-id (i-xxxxxxxx)\n      - ec2_id # Transforms instance-id -\u003e PrivateIpAddress\n\n  - name: /usr/local/bin/packer\n    wrapper: packer\n    transformers:\n      - yaml2json # Converts yaml to json\n```\n\nLets test out the `ec2_id` and `ec2_name` filters using `dargs run`.\n```\n# -n = dry run, only print what would have been executed\n$ dargs run -n -- ssh i-05d3e9e370805d0b2\nssh 10.0.0.9\n\n# Same instance but now I'm passing in the instance name\n# This was processed by both transformers, try running with `-d` to see what's happening\n$ dargs run -n -- ssh ec2:test\nssh 10.0.0.9\n\n# We can pass in the transformers on the command line and run any command with dargs.\n# The ~/.dargs.yml config allows us to omit the --transformers, -t flag for commands defined in it\n$ dargs run -t ec2_id -- echo i-05d3e9e370805d0b2\n10.0.0.9\n\n# Here's an example of the yaml2json filter using cat\n$ cat /tmp/test.yml\n---\nfoo: bar\nmoo: cow\n\n# -v is verbose, prints out the command before executing it\n$ dargs run -v -t yaml2json -- cat /tmp/test.yml\ncat /tmp/test.json\n{\n  \"foo\": \"bar\",\n  \"moo\": \"cow\"\n}\n```\n\nTyping all that out wouldn't be very efficient. To make this simpler we can either:\n```\nalias ssh='dargs run -- ssh'\n```\nOR:\n```\n$ dargs generate-bins\nINFO Wrote /home/***/bin/ssh\nINFO Wrote /home/***/bin/packer\n\n# and ensure ~/bin has high precidence in your PATH\n$ export PATH=$HOME/bin:$PATH\n```\n\nLets test out completions\n```\n$ dargs generate-completions -f\nINFO Wrote /home/***/.dargs/completions/bash/zzdargs_ssh\nINFO Wrote /home/***/.dargs/completions/bash/zzdargs_packer\n\n$ source ~/.dargs/completions/bash/*\n\n$ ssh ec2:te\u003ctab\u003e\n\n# We can run the dargs completion command stand-alone to see the results\n# syntax: dargs completions -- command prev_arg current_arg\n$ dargs completions -- ssh \"\" \"ec2:te\"\nec2:test\n```\n\n## Manual\n\n### Commands\nDargs commands:\n* `dargs run [flags] -- command command_args..`\n  * Transforms arguments and runs command.\n* `dargs generate-bins`\n  * Generate wrapper bin scripts, alternative to `alias cmd='dargs run -- cmd'`\n* `dargs generate-completions [flags]`\n  * Generate bash/zsh completion scripts\n* `dargs complete -- cmd prev_arg cur_arg`\n  * Used by bash/zsh completion scripts, useful for debugging\n\n### The dargs config file: ~/.dargs.yml\n\n**Note:** You can find example dargs config files in the [examples](examples/) folder of this repo.\n\nDargs configuration consists of four top level keys:\n* **imports**    - Import dargs config from file glob or URLs\n* **transformers** - Transform matching CLI args before executing the command\n* **completers** - Complete matching CLI args\n* **commands**   - Mapping transformers/completers to commands\n\n```yaml\n# Files to import transformers, completers, and (optionally) commands from\nimports:\n  # Can be url\n  - https://raw.githubusercontent.com/aelsabbahy/dargs/master/examples/quick_start.yml\n  # Local path or glob\n  - ~/.dargs/config.d/*.yml\n\n# These transform CLI arguments\ntransformers:\n    # Name of transformer\n  - name: ec2_id\n    # Transformer only runs on CLI args matching this regex\n    # Regex groups are available as $RE_0, $RE_1 or if named group $RE_GROUPNAME\n    match: '^i-[0-9a-z]+$'\n    # (optional) Only match if the previous argument also matches this regex\n    # prev-match: '--some-flag'\n    # Seconds to cache results (604800 seconds = 1 week)\n    cache: 604800\n    # Command to run, replacing argument with output of the command\n    # To convert an argument into many arguments, use newline as a separator\n    # Example:\n    # echo -e '-i\\n~/.ssh/some_key.pem\\n10.11.12.13'\n    # Will expand into -i ~/.ssh/some_key.pem 10.11.12.13\n    command: |\n      aws ec2 describe-instances \\\n        --filters 'Name=instance-state-name,Values=running' --instance-ids \"$RE_0\" \\\n        --query 'Reservations[*].Instances[*].[PrivateIpAddress]' --output text\n\n# These complete CLI arguments\ncompleters:\n    # name, match, prev-match, cache have same meaning as transformers\n    - name: ec2_name\n      match: '^ec2:(?P\u003cname_prefix\u003e.+)$'\n      cache: 120\n      # Newline separated list of completions\n      command: |\n      aws ec2 describe-instances \\\n      --filters \"Name=tag:Name,Values=${RE_name_prefix}*\" 'Name=instance-state-name,Values=running' \\\n      --query \"Reservations[*].Instances[*].[Tags[?Key=='Name'].Value]\" --output text | sed -e \"s/^/ec2:/\"\n\ncommands:\n    # Command to match\n  - name: /usr/bin/ssh\n    # Wrapper name when running `dargs generate-bins`\n    wrapper: ssh\n    # Use fzf to fuzzy complete (must have fzf installed)\n    #fzf-complete: true\n    # List of completers/transformers to associate with this command by default\n    completers:\n      - ec2_name\n    # Transformers are run in order which allows them to be chained\n    transformers:\n      - ec2_id\n```\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faelsabbahy%2Fdargs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faelsabbahy%2Fdargs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faelsabbahy%2Fdargs/lists"}