{"id":15619664,"url":"https://github.com/kolotaev/argsy","last_synced_at":"2025-10-24T14:45:49.206Z","repository":{"id":62553498,"uuid":"169231492","full_name":"kolotaev/argsy","owner":"kolotaev","description":"Tiny \"commands \u0026 options\" DSL for your CLI scripts","archived":false,"fork":false,"pushed_at":"2019-02-08T13:02:56.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-07T22:15:27.658Z","etag":null,"topics":["cli","dsl","ruby","snippet"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kolotaev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-05T11:38:36.000Z","updated_at":"2021-10-12T10:54:53.000Z","dependencies_parsed_at":"2022-11-03T04:15:51.582Z","dependency_job_id":null,"html_url":"https://github.com/kolotaev/argsy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kolotaev%2Fargsy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kolotaev%2Fargsy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kolotaev%2Fargsy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kolotaev%2Fargsy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kolotaev","download_url":"https://codeload.github.com/kolotaev/argsy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246204741,"owners_count":20740374,"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":["cli","dsl","ruby","snippet"],"created_at":"2024-10-03T08:40:53.942Z","updated_at":"2025-10-24T14:45:49.118Z","avatar_url":"https://github.com/kolotaev.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Argsy\n\nTiny helper snippet you can paste into your CLI script(s) to obtain \"commands + options\" DSL without\nexternal dependencies.\n\n[![Build](https://travis-ci.org/kolotaev/argsy.svg?branch=master)](https://travis-ci.org/kolotaev/argsy)\n[![Gem Version](https://badge.fury.io/rb/argsy.svg)](https://badge.fury.io/rb/argsy)\n[![License](https://upload.wikimedia.org/wikipedia/commons/e/ee/Unlicense_Blue_Badge.svg)](https://raw.githubusercontent.com/kolotaev/argsy/master/LICENSE.txt)\n\n## Rationale\n\nAs you already know, Ruby is awesome for scripting and any sort of CLI tools: it gives you a superb OS commands \ninteraction interface, JSON/YAML parsing, HTTP tools, etc... All out of the box! But built-in `OptionParser` doesn't\nprovide easy-to-write functionality to create CLIs like `./script command --option 1`. The problem here is: how to\ndeclare command, action and options conveniently?\n\n\u003e Sometimes, for any imaginable reason, you do not want you script to be dependent on external gems (say, you want to\n\u003e pass a script that \"just works!\" to your co-workers without telling them \"Hey, you also need to install this or that \n\u003e gem\")\n\n`Argsy` gives you such possibility. It's [just 17 lines of code](lib/argsy.rb), published under `The Unlicense`, \nso you can just copy-paste it inside your script and have a nice \ntiny DSL. You can of course use it as a gem as well, if you want to.\n\n**Disclaimer**: `Argsy` doesn't claim itself as a profound CLI DSL like `Thor` and the company, \nthus for complex scripts, please, opt for those gems instead.\n\n## Usage\n\n```ruby\nArgsy.new '1.0.0' do\n  command :list, 'List all files' do\n    action do |o|\n      puts %w(. .. .hidden.py).join(\"\\n\") if o[:all]\n      puts %w(todos.txt recipes.doc).join(\"\\n\")\n      puts \"me.#{o[:extension]}\" if o[:extension]\n    end\n    options do\n      on '-a', '--all', 'Show all, even hidden files'\n      on '-e', '--extension EXTENSION', 'List available files with extension'\n    end\n  end\n  \n  command 'print', 'Print all given options' do\n    action \u0026method(:puts)\n    options do\n      on '-a', '--A', 'A option'\n      on '-b', 'B option'\n    end\n  end\n  \n  command 'world:hello', 'Greet the World group without options' do\n    action { puts 'Hello world!' }\n  end\n  \n  command 'world:bye', 'Say goodbye to the World group without options' do\n    action { puts 'World, I bid you farewell!' }\n  end\n  \n  command :post do |c|\n    action do |opts|\n      puts \"I'm a command without description\"\n      puts \"Posting to facebook: #{opts[:message]}\" if opts[:facebook]\n      puts \"Posting to twitter: You're Tearing Me Apart, Lisa!\" if opts[:twitter]\n      puts \"Date and time posted: #{opts[:date]}\"\n    end\n    options do\n      require 'optparse/time'\n      on_tail '-d', '--date=DATE', Time, 'Date when message was posted'\n      on '-f', '--facebook' do\n        c.opts[:message] = 'Oh, Hi Mark'\n      end\n      on '-t', '--twitter'\n    end\n  end\nend.run\n```\n\nIn console:\n```\n$ ./example\nUsage: example CMD [--help] [--version]\n    list                             List all files\n    print                            Print all given options\n    world:hello                      Greet the World group without options\n    world:bye                        Say goodbye to the World group without options\n    post                             \n\n$ ./example post --help\nUsage: example post [options] [--help]\n    -f, --facebook\n    -t, --twitter\n    -d, --date=DATE                  Date when message was posted\n\n$ ./example post -f -d 12-8-2016\nI'm a command without description\nPosting to facebook: Oh, Hi Mark\nDate and time posted: 2016-08-12 00:00:00 +0300\n\n$ ./example --version\nexample version 1.0.0\n```\n\n## FAQ\n\n| Q:       | A:          |\n| ------------- |-------------|\n| Does it support groups/subcommands?      | Only in a way of declaring commands as `'group:subcommand'`      |\n| What can I do inside options block?      | Anything that is possible inside a stdlib's `OptionParser`      |\n| Why not Thor, Commander, etc.?     | See rationale |\n| Can I use it as a gem?    | Yes. `gem install argsy` |\n| Why does it look like a minified jQuery?      | Yes, it's not an idiomatic Ruby formatting. I wanted to make it terse, still readable |\n| Copy-pasting is bad. It's not DRY!      | Absolutely agree with you |\n\n## License\nThe Unlicense\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkolotaev%2Fargsy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkolotaev%2Fargsy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkolotaev%2Fargsy/lists"}