Giter VIP home page Giter VIP logo

Comments (7)

balupton avatar balupton commented on June 4, 2024 1

Would be cool if each command or group of commands also hd a video tutorial, which the help prompt after dumping the usage data, does a confirm prompt if they want to open the video tutorial. It can go on the bevry software channel.

from dorothy.

balupton avatar balupton commented on June 4, 2024 1

Found these.

https://en.wikipedia.org/wiki/Command-line_interface#Command_description_syntax

  • angle brackets for required parameters: ping
  • square brackets for optional parameters: mkdir [-p]
  • ellipses for repeated items: cp [source2…]
  • vertical bars for choice of items: netstat {-t|-u}

As such, ellipses inside the bracket, at the end. Square brackets denote exclusive options.

https://linux.die.net/man/7/man-pages

For commands, this shows the syntax of the command and its arguments (including options); boldface is used for as-is text and italics are used to indicate replaceable arguments. Brackets ([]) surround optional arguments, vertical bars (|) separate choices, and ellipses (...) can be repeated.

Also, it states several sections and what is expected in those sections...

The following list elaborates on the contents of each of the above sections.
...


As such, something like this:

cat <<-EOF >/dev/stderr
	USAGE:
	get-profile <property> -- ...<source>

	ARGUMENTS:
	<property> can be any of these: ${property_options[*]}>
	<source> can be any multiple of these: ${source_options[*]}
	<source> also supports ... which will be expanded to all of options

	RETURNS:
	Success if there was a value. Value will be outputted.
	Failure if no value was found. Nothing will be outputted.
EOF

Becomes this:

CleanShot 2021-12-05 at 10 20 41@2x

and the much more complex code:

cat <<-EOF >/dev/stderr
	$(echo-style --h1='SYNOPSIS')
	$(
		echo-style \
			--bold='get-profile ' \
			--italic='<' \
			--bold="$(
				echo-join \
					"$(
						echo-style --disable-bold+italic='|' --bold
					)" \
					-- "${property_options[@]}"
			)" \
			--disable-bold+italic="> [" \
			--bold='-- ' \
			--italic='...<' \
			--bold="$(
				echo-join \
					"$(
						echo-style --disable-bold+italic='|' --bold
					)" \
					-- "${source_options[@]}" '...'
			)" \
			--disable-bold+italic='>]'
	)

	$(echo-style --h1='OPTIONS')
	$(
		echo-style \
			--bold='get-profile ' \
			--italic='<property> [' \
			--bold='-- ' \
			--italic='...<source>]'
	)

	<property>  can be any of these:
					$(echo-join ', ' -- "${property_options[@]}")

	<source>    can be any multiple of these:
					$(echo-join ', ' -- "${source_options[@]}" '...')

					if ... is used, the ... will expand to all sources

	$(echo-style --h1='EXIT STATUS')
	Success if there was a value. Value will be outputted.
	Failure if no value was found. Nothing will be outputted.
EOF

note that the unix convention of ... inside to specify recurrance doesn't work, as ... inside means an option, as such, we will break the unix convention, and place repitition indicators outside


Alright, settling on this:

CleanShot 2021-12-05 at 11 10 15@2x

	cat <<-EOF >/dev/stderr
		$(echo-style --h1='SYNOPSIS')
		$(
			echo-style \
				--bold='get-profile ' \
				--italic='[' \
				--bold="$(
					echo-join \
						"$(
							echo-style --disable-bold+italic='|' --bold
						)" \
						-- "${property_options[@]}"
				)" \
				--disable-bold+italic="] [" \
				--bold='-- ' \
				--italic='...[' \
				--bold="$(
					echo-join \
						"$(
							echo-style --disable-bold+italic='|' --bold
						)" \
						-- "${source_options[@]}" '...'
				)" \
				--disable-bold+italic=']]'
		)

		$(echo-style --h1='DESCRIPTION')
		Attempts to retrieve a profile property from one or more sources.

		$(echo-style --h1='CONFIGURATION')
		The $(echo-style --bold='profile.bash') configuration file will be sourced.

		$(echo-style --h1='OPTIONS')
		$(
			echo-style \
				--bold='get-profile ' \
				--italic='[property] [' \
				--bold='-- ' \
				--italic='...[source]]'
		)

		$(echo-style --italic='property')
		    if provided, it must be one of these values:
		        $(
			echo-style --bold="$(
				echo-join "$(
					echo-style --disable-bold+italic=', ' --bold
				)" -- "${property_options[@]}"
			)"
		)
		    if omitted, you will be prompted to make a selection.

		$(echo-style --italic='source')
		    if provided, it must be one or more of these values:
		        $(
			echo-style --bold="$(
				echo-join "$(
					echo-style --disable-bold+italic=', ' --bold
				)" -- "${source_options[@]}" '...'
			)"
		)
		    if omitted, all sources will be used.
		    if $(echo-style --bold='...') is used, it will be expanded to all sources.

		$(echo-style --h1='EXIT STATUS')
		$(echo-style --green='[0] if a value was found.')
		stdout will output the fetched value.
		stderr will be empty.

		$(echo-style --red='[6 Device not configured] if no value was found.')
		stdout will be empty.
		stderr will output that the result is undefined.

		$(echo-style --h1='EXAMPLES')
		Attempt to retrieve the name from the first available source, these are all equivalent:

		    $(echo-style --bold='get-profile name')
		    $(echo-style --bold='get-profile name --')
		    $(echo-style --bold='get-profile name -- ...')

		Attempt to retrieve the name from only npm:

		    $(echo-style --bold='get-profile name -- npm')

		Attempt to retrieve the name from the first available source, starting with npm, then git:

		    $(echo-style --bold='get-profile name -- npm git ...')
	EOF

from dorothy.

balupton avatar balupton commented on June 4, 2024

Rather than man pages for each command, it is best to do --help flags for each of them, as it is easier and more robust, for example:

dorothy/commands/ask

Lines 5 to 25 in fe27c95

# help
if is-help "$@"; then
stderr echo-lines \
'ABOUT:' \
'Prompt the user for an input value in a clean and robust way.' \
'' \
'USAGE:' \
'ask [...flags]' \
'ask [...flags] <--flag=...> -- <...args>' \
'' \
'FLAGS:' \
'Provide [--question=...] to specify the question that the prompt will be answering.' \
'Provide [--default=...] to specify the default value if no user specified value is entered.' \
'Provide [--confirm] to specify that the prompt should confirm the value before continuing.' \
'Provide [--password] to specify that the prompt should hide the value when entering by using password mode.' \
'Provide [--required] to specify that the prompt should not continue until a value is provided.' \
'Provide [--timeout=...] to specify a custom timeout value in seconds.' \
'Provide [--flag=...] -- <...args> to specify a flag to search the arguments for, to set a default value.' \
'Provide [--main] to not create an alternative TTY shell when promting for questions.'
exit 22 # Invalid argument
fi

from dorothy.

balupton avatar balupton commented on June 4, 2024

For convention, I believe this one is good enough to roll out to the rest:

0d58b42

from dorothy.

balupton avatar balupton commented on June 4, 2024

@molleweide can I assign this to you?

from dorothy.

balupton avatar balupton commented on June 4, 2024

For implementation, we should note a better way of doing the multiline echos

#45

from dorothy.

molleweide avatar molleweide commented on June 4, 2024

@molleweide can I assign this to you?

Yo I'll try to look at this and see what I can do.

from dorothy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.