{"id":13448472,"url":"https://github.com/nk412/optparse","last_synced_at":"2025-07-23T22:42:38.456Z","repository":{"id":10563557,"uuid":"12766754","full_name":"nk412/optparse","owner":"nk412","description":"Simple command line arguments parser for BASH","archived":false,"fork":false,"pushed_at":"2022-01-01T16:33:06.000Z","size":13,"stargazers_count":159,"open_issues_count":19,"forks_count":32,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-08T00:58:19.095Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","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/nk412.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":"2013-09-11T20:21:15.000Z","updated_at":"2024-12-03T01:17:28.000Z","dependencies_parsed_at":"2022-09-18T20:21:39.491Z","dependency_job_id":null,"html_url":"https://github.com/nk412/optparse","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/nk412%2Foptparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nk412%2Foptparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nk412%2Foptparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nk412%2Foptparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nk412","download_url":"https://codeload.github.com/nk412/optparse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244937751,"owners_count":20535124,"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-07-31T05:01:46.585Z","updated_at":"2025-03-22T09:31:23.127Z","avatar_url":"https://github.com/nk412.png","language":"Shell","readme":"# Optparse\nA BASH wrapper for getopts, for simple command-line argument parsing\n\n### ( ! ) ATTENTION MAC USERS\nOptparse requires `gnu-sed` instead of the default Mac version of sed, which you can do with the following:\n```\nbrew install gnu-sed --with-default-names\n```\n\n## What is this?\nA wrapper that provides a clean and easy way to parse arguments to your BASH scripts. It lets you define short and long option names, handle flag variables, and set default values for optional arguments, all while aiming to be as minimal as possible: *One line per argument definition*.\n\n## Usage\n##### See `sample_head.sh` for a demonstration of optparse\n### 1. Define your arguments\n\nEach argument to the script is defined with `optparse.define`, which specifies the option names, a short description, the variable it sets and the default value (if any). \n\n```bash\noptparse.define short=f long=file desc=\"The input file\" variable=filename\n```\n\nFlags are defined in exactly the same way, but with an extra parameter `value` that is assigned to the variable. \n\n```bash\noptparse.define short=v long=verbose desc=\"Set flag for verbose mode\" variable=verbose_mode value=true default=false\n```    \n\n### 2. Evaluate your arguments\nThe `optparse.build` function creates a temporary header script based on the provided argument definitions. Simply source the file the function returns, to parse the arguments.\n\n```bash\nsource $( optparse.build )\n```\n\n#### That's it!\nThe script can now make use of the variables. Running the script (without any arguments) should give you a neat usage description.\n    \n    usage: ./script.sh [OPTIONS]\n    \n    OPTIONS:\n    \n        -f --file  :  The input file\n    \t-v --verbose  :  Set flag for verbose mode\n    \n    \t-? --help  :  usage\n        \n## Supported definition parameters\nAll definition parameters for `optparse.define` are provided as `key=value` pairs, seperated by an `=` sign.\n#### `short`\na short, single-letter name for the option\n#### `long`\na longer expanded option name\n#### `variable`\nthe target variable that the argument represents\n#### `value`(optional)\nthe value to set the variable to. If unspecified, user is expected to provide a value.\n#### `desc`(optional)\na short description of the argument (to build the usage description)\n#### `default`(optional)\nthe default value to set the variable to if argument not specified\n\n## Installation\n1. Download/clone `optparse.bash`\n2. Add \n\n```bash    \n`source /path/to/optparse.bash` \n```\nto `~/.bashrc`\n\n","funding_links":[],"categories":["Shell","Shell Script Development"],"sub_categories":["Directory Navigation"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnk412%2Foptparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnk412%2Foptparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnk412%2Foptparse/lists"}