https://github.com/semk/argparse
Simple and elegant command line argument parser for shell scripts.
https://github.com/semk/argparse
argparse argument-parser bash golang
Last synced: about 2 months ago
JSON representation
Simple and elegant command line argument parser for shell scripts.
- Host: GitHub
- URL: https://github.com/semk/argparse
- Owner: semk
- License: mit
- Created: 2020-03-23T07:20:23.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-27T14:39:43.000Z (about 5 years ago)
- Last Synced: 2024-06-20T10:15:41.486Z (almost 2 years ago)
- Topics: argparse, argument-parser, bash, golang
- Language: Go
- Homepage:
- Size: 23.4 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# argparse
Simple and elegant command line argument parser for scripts that can be used as a shebang (Bash | Python | Perl etc.)
## Installation
```
go get github.com/semk/argparse
cp $(go env GOPATH)/bin/argparse /usr/local/bin
```
## Usage
```
Usage of ./argparse:
-arg value
Define custom argument to the program. Format: name::default:desc
-executor string
Path to the script executor (set this to shebang (#!)) (default "/bin/bash")
```
And the last arguments can be the script with the arguments to be called.
### in scripts #!
```
#!/usr/local/bin/argparse --executor=/bin/bash --arg=name::NoNameDefined::Name
```
### direct usage
```
argparse --executor=/bin/bash --arg=name::NoNameDefined::Name printname.sh --name Sreejith
```
The defined args would then be available as capitalized envirionment variables with the `ARG_` format.
## Example
This example shows how `argparse` can be used as a `#!` in a `bash` script for commandline parsing. The following file is named `printname.sh`.
```
#!/usr/local/bin/argparse --executor=/bin/bash --arg=name::NoNameDefined::Name
echo "This program prints names passed to the argument --name."
echo "Name: ${ARG_NAME}"
```
```
$ ./printname.sh --name Sreejith
This program prints names passed to the argument --name.
Name: Sreejith
```
```
$ ./printname.sh
This program prints names passed to the argument --name.
Name: NoNameDefined
```
```
$ ./printname.sh --help
Usage of ./printname.sh:
-name string
Name (default "NoNameDefined")
```