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

Add support for optional arguments and/or getopt-style options #51

Closed
lkrms opened this issue Aug 2, 2022 · 0 comments
Closed

Add support for optional arguments and/or getopt-style options #51

lkrms opened this issue Aug 2, 2022 · 0 comments

Comments

@lkrms
Copy link

lkrms commented Aug 2, 2022

Great project! Thanks for all of your work on it 🙌🏻

Before I can convert my function docs to shdoc annotations, I need to find a way to mark arguments as optional, i.e. something equivalent to this:

# my_func REQUIRED_ARG [OPTIONAL_ARG]
my_func() {
  # ...
}

A few possibilities for the melting pot of ideas:

  1. @arg?
# @arg $1 string A required argument.
# @arg? $2 string An optional argument.
  1. @arg [$2]
# @arg $1 string A required argument.
# @arg [$2] string An optional argument.
  1. @arg ?$2
# @arg $1 string A required argument.
# @arg ?$2 string An optional argument.

Non-positional arguments a.k.a. getopt-style options

I don't have suggested syntax ready to go, but annotations to add support for getopt-style options (flags, values, optional values) would be excellent.

These are typically described as follows, where REQUIRED and OPTIONAL are positional:

# my_func [-f] [-w VALUE] [-wOPTIONAL_VALUE] REQUIRED [OPTIONAL...]

Caveats

More complex arrangements would probably be too difficult to design intuitive annotation syntax for and could be explained in @description if needed:

# my_func REQUIRED_ARG [[OPTIONAL_ARG2] OPTIONAL_ARG]

That said, maybe an optional @synopsis tag or similar could be used to provide a compact one-line summary using agreed syntax à la docopt:

# @synopsis my_func <required_arg> [[optional_arg2] optional_arg]

A default synopsis could be generated from @arg annotations if not given explicitly.

landure added a commit to landure/shdoc that referenced this issue Aug 17, 2023
…st#64)

* Add missing empty line in overview section output.

* - Add @option for short option (-o) and long options (--option).
- Revamp description and titles processing to normalize "\n" usage and remove empty lines at the start and end of description.
- Add dt and dd rendering styles.

* Add @option to README and example.

* Remove useless description  self-assignation.

* Fix readme width after adding too long @option

* Fix readme width by shorting @see example.

* Fix missing < and > escaping in outputted markdown
landure added a commit to landure/shdoc that referenced this issue Aug 17, 2023
…st#64)

* Add missing empty line in overview section output.

* - Add @option for short option (-o) and long options (--option).
- Revamp description and titles processing to normalize "\n" usage and remove empty lines at the start and end of description.
- Add dt and dd rendering styles.

* Add @option to README and example.

* Remove useless description  self-assignation.

* Fix readme width after adding too long @option

* Fix readme width by shorting @see example.

* Fix missing < and > escaping in outputted markdown
landure added a commit to landure/shdoc that referenced this issue Aug 17, 2023
…st#64)

* Add missing empty line in overview section output.

* - Add @option for short option (-o) and long options (--option).
- Revamp description and titles processing to normalize "\n" usage and remove empty lines at the start and end of description.
- Add dt and dd rendering styles.

* Add @option to README and example.

* Remove useless description  self-assignation.

* Fix readme width after adding too long @option

* Fix readme width by shorting @see example.

* Fix missing < and > escaping in outputted markdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant