Skip to content
/ ramen Public

๐Ÿœ An easier way to define and parse arguments in SHELL scripts. getopts alternative.

License

Notifications You must be signed in to change notification settings

ggicci/ramen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

19 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ramen ๐Ÿœ

An easier way to define and parse arguments in SHELL scripts. Why ramen?

Enjoy your SHELL scripting!

Usage

#!/usr/bin/env bash

set -euo pipefail

ARGUMENT_PARSER='
version: "1.0"
program: upload
args: [SRC, DST, -v/--verbose, -t/--threads, --protocol]
'

main() {
  eval "$( ramen "$ARGUMENT_PARSER" -- "$@" )"

    echo "
SRC: $SRC
DST: $DST
verbose: $verbose
threads: $threads
protocol: $protocol
"
}

main "$@"

More granual control over arguments:

ARGUMENT_PARSER='
version: "1.0"
program: upload
output_prefix: ramen_
args:
  - name: SRC
  - name: DST
  - name: verbose
    short: -v
    long: --verbose
    type: boolean
  - name: threads
    short: -t
    long: --threads
    type: number
    default: 8
  - name: protocol
    short: -p
    long: --protocol
    type: string
    default: scp
    select: [scp, rsync, aws]
'

FAQ

Why ramen? Not getopt or getopts?

Iโ€™ve never been a fan of getopt or getopts. Thatโ€™s why I created ramen. Despite spending countless hours reading their documentation and following community examples, I always came away empty-handed, unable to retain anything. For me, learning either of the two just isnโ€™t worth the effort.

ramen takes a different approach by allowing you to define the argument parser in a descriptive YAML format. This simplifies the syntax while leveraging the powerful parsing capabilities of clap.

I know ramen is still in its early stages, but I hope it can save us time and effort when implementing argument parsers for SHELL scripts.

Why getopts, not ramen?

getopts comes along with the Linux system, ramen doesn't.

About

๐Ÿœ An easier way to define and parse arguments in SHELL scripts. getopts alternative.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published