Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] - getopts - parse cli arguments #9

Closed
nyxnor opened this issue Nov 18, 2021 · 3 comments
Closed

[FEATURE REQUEST] - getopts - parse cli arguments #9

nyxnor opened this issue Nov 18, 2021 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@nyxnor
Copy link
Owner

nyxnor commented Nov 18, 2021

Describe the solution you'd like

I want getopts to parse cli arguments. It will be cleaner.

Describe alternatives you've considered

Additional context

Have no time to do this right now, but it is a medium priority goal.

@nyxnor nyxnor added enhancement New feature or request help wanted Extra attention is needed labels Nov 18, 2021
@nyxnor nyxnor changed the title [FEATURE REQUEST] [FEATURE REQUEST] - getopts - parse cli arguments Nov 18, 2021
@nyxnor
Copy link
Owner Author

nyxnor commented Nov 18, 2021

Imagine using default options and omitting them. as in HiddenServiceVersion, the only available v now it 3, so it can default to 3, but when v4 comes out, it will default to the greatest/more secure version and let both be options.
There are many more things that can be improved with getopts.

@nyxnor nyxnor added this to the 0.0.1 milestone Nov 28, 2021
@nyxnor
Copy link
Owner Author

nyxnor commented Nov 28, 2021

Implementiong bare hands because posix getopts is horrible for only short options and getoptions is out of my league.

while true; do
  case "${1}" in
    on|off|list|renew|web|location|backup|restore|vanguards) command="${1}"; shift;;

    auth-server|auth-client) command="${1%-*}"; host="${1#*-}"; : "${host:?$(error_msg "host is missing")}"; shift;;

    --install|--logs|--upgrade|--remove|--nginx|--apache|--html|--create|--integrate) action="${1}"; shift;;

    --on|--off|--list) status="${1}"; shift;;

    -s|--service) service="${2:?$(error_msg "service is missing")}"; shift 2;;
    --service=*) service="${1#*=}"; : "${service:?$(error_msg "service is missing")}"; shift;;

    -c|--client) client="${2:?$(error_msg "client is missing")}"; shift 2;;
    --client=*) client="${1#*=}"; : "${client:?$(error_msg "client is missing")}"; shift;;

    -o|--onion) onion="${2:?$(error_msg "onion is missing")}"; shift 2;;
    --onion=*) onion="${1#*-}"; : "${onion:?$(error_msg "onion is missing")}"; shift;;

    -P|--purge) purge="${1}"; shift;;

    -v|--version) version="${2:?$(error_msg "version is missing")}"; shift 2;;
    --version=*) version="${1#*=}"; : "${version:=3}"; shift;;

    -S|--socket) socket="${2:?$(error_msg "socket is missing")}"; shift 2;;
    --socket=*) socket="${1#*=}"; : "${socket:?$(error_msg "socket is missing")}"; shift;;

    -p|--port) port="${2:?$(error_msg "port is missing")}"; shift 2;;
    --port=*) port="${1#*=}"; : "${ports:?$(error_msg "port is missing")}"; shift;;

    --path) path="${2:?$(error_msg "path is missing")}"; shift 2;;
    --path=*) path="${1#*=}"; : "${path:?$(error_msg "path is missing")}"; shift;;

    --) shift; break;;
    *) break;;
  esac
done

@nyxnor nyxnor closed this as completed in 7d020a7 Nov 29, 2021
@nyxnor
Copy link
Owner Author

nyxnor commented Nov 29, 2021

available args:

--service ssh,xmpp
--service=ssh,xmpp
--service "ssh xmpp"
--service "ssh,xmpp"

So basically anything to fit any need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant