Commit Graph

31 Commits

Author SHA1 Message Date
Fabian Boehm
f9635b1a04 docs/argparse: Explain dashes in flag names 2024-09-15 09:39:09 +02:00
Fabian Boehm
94d3307469 docs/argparse: Add some more examples, something on -x
Fixes #10284
2024-02-03 21:41:50 +01:00
Fabian Boehm
f8cb8284b2 docs: Add argparse examples on how to use the flags 2024-01-14 10:20:11 +01:00
mattmc3
cd17c1281d
Add argparse validation examples (#9483)
* Add argparse validation examples

* Remove invalid example
2023-01-19 11:06:51 +01:00
Fabian Boehm
a99f588328 docs: More on bool flags
Instead of duplicating this, just point above.
2022-10-07 16:11:45 +02:00
Fabian Boehm
e62af43d12 docs: Fix how bool flag vars are set
This was changed for #4226, shortly after argparse was implemented.

Fixes #9265
2022-10-07 15:48:24 +02:00
Fabian Boehm
38b24c2325 docs: Use :doc: role when linking to commands
This makes it so we link to the very top of the document instead of a
special anchor we manually include.

So clicking e.g. :doc:`string <cmds/string>` will link you to
cmds/string.html instead of cmds/string.html#cmd-string.

I would love to have a way to say "this document from the root of the
document path", but that doesn't appear to work, I tried
`/cmds/string`.

So we'll just have to use cmds/string in normal documents and plain
`string` from other commands.
2022-09-24 10:56:43 +02:00
Fabian Boehm
993448d552 argparse: Allow usage without optspecs
It's still useful without, for instance to implement a command that
takes no options, or to check min-args or max-args.

(technically no optspecs, no min/max args and --ignore-unknown does
nothing, but that's a very specific error that we don't need to forbid)

Fixes #9006
2022-06-27 17:02:20 +02:00
David Adam
3a23fdf359 docs: omnibus cleanup
Includes harmonizing the display of options and arguments, standardising
terminology, using the envvar directive more broadly, adding help options to all
commands that support them, simplifying some language, and tidying up multiple
formatting issues.

string documentation is not changed.
2022-03-12 00:21:13 +08:00
David Adam
e23e52a8e9 docs: standardise on definition lists for options
Harmonizes the option listing including formatting in a similar manner to the
synopsis of each entry.
2022-03-12 00:21:12 +08:00
Johannes Altmanninger
c0d1e41313 docs synopsis: add HTML highlighing and automate manpage markup
Recent synopsis changes move from literal code blocks to
[RST line blocks].  This does not translate well to HTML: it's not
rendered in monospace, so aligment is lost.  Additionally, we don't
get syntax highlighting in HTML, which adds differences to our code
samples which are highlighted.

We hard-wrap synopsis lines (like code blocks). To align continuation
lines in manpages we need [backslashes in weird places]. Combined with
the **, *, and `` markup, it's a bit hard to get the alignment right.

Fix these by moving synopsis sources back to code blocks and compute
HTML syntax highlighting and manpage markup with a custom Sphinx
extension.

The new Pygments lexer can tokenize a synopsis and assign the various
highlighting roles, which closely matches fish's syntax highlighing:
- command/keyword (dark blue)
- parameter (light blue)
- operator like and/or/not/&&/|| (cyan)
- grammar metacharacter (black)

For manpage output, we don't project the fish syntax highlighting
but follow the markup convention in GNU's man(1):

	bold text          type exactly as shown.
	italic text        replace with appropriate argument.

To make it easy to separate these two automatically, formalize that
(italic) placeholders must be uppercase; while all lowercase text is
interpreted literally (so rendered bold).
This makes manpages more consistent, see string-join(1) and and(1).

Implementation notes:
Since we want manpage formatting but Sphinx's Pygments highlighing
plugin does not support manpage output, add our custom "synopsis"
directive.  This directive parses differently when manpage output is
specified. This means that the HTML and manpage build processes must
not share a cache, because the parsed doctrees are cached.  Work around
this by using separate cache locations for build targets "sphinx-docs"
(which creates HTML) and "sphinx-manpages".  A better solution would
be to only override Sphinx's ManualPageBuilder but that would take a
bit more code (ideally we could override ManualPageWriter but Sphinx
4.3.2 doesn't really support that).

---

Alternative solution: stick with line blocks but use roles like
:command: or :option: (or custom ones). While this would make it
possible to produce HTML that is consistent with code blocks (by adding
a bit of CSS), the source would look uglier and is harder to maintain.
(Let's say we want to add custom formatting to the [|] metacharacters
in HTML.  This is much easier with the proposed patch.)

---

[RST line blocks]: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#line-blocks
[backslashes in weird places]: https://github.com/fish-shell/fish-shell/pull/8626#discussion_r782837750
2022-01-19 22:56:41 +08:00
Johannes Altmanninger
ad4530acd3 docs synopses: add space before ellipsis
This matches the style in man(1) (except that we use the … ligature).

A previous iteration did the reverse (never use a space before the
ellipsis). That would be a smaller change.
2022-01-16 14:05:47 +01:00
Fabian Homborg
0781473564 argparse: Jump to the next option after an unknown one
Previously, when we got an unknown option with --ignore-unknown, we
would increment woptind but still try to read the same contents.

This means in e.g.

```
argparse -i h -- -ooo -h
```

The `-h` would also be skipped as an option, because after the first
`-o` getopt reads the other two `-o` and skips that many options.

This could be handled more extensively in wgetopt, but the simpler fix
is to just skip to the next argv entry once we have an unknown option
- there's nothing more we can do with it anyway!

Additionally, document this and clearly explain that we currently
don't transform the option.

Fixes #8637
2022-01-15 12:17:43 +01:00
Aaron Gyes
79d1b3e085 slog through documentation
I did.. a and b today.
2021-12-09 03:34:28 -08:00
Fabian Homborg
58177ba091 docs: Replace all internal links with :ref:s
Unlike links, these are checked by sphinx and it complains if they
don't match.

Also they have a better chance of doing something useful in outputs
other than html.
2021-03-26 19:32:14 +01:00
Michael Jarvis
496d7c44a1 Fix sphinx doc warning
~/src/fish-shell/doc_src/cmds/argparse.rst:103: WARNING: Literal block ends without a blank line; unexpected unindent.
~/src/fish-shell/doc_src/cmds/argparse.rst:103: WARNING: Literal block ends without a blank line; unexpected unindent.
2021-02-05 11:07:58 +01:00
Fabian Homborg
3eef295990 docs/argparse: Remove more of the vestigial shortopt mentions
It should only be mentioned as a backwards-compatibility measure,
because it is useless - not even the short flag variable is set.
2021-02-03 19:13:53 +01:00
Fabian Homborg
8bb3d1198f docs: Make code lines shorter 2021-02-02 08:29:31 +01:00
Fabian Homborg
b43a8688fe docs: Correct argparse on short- options
These aren't exposed as variables at all, so it's just entirely
vestigial now and only kept for backwards compatibility.
2021-01-01 14:22:22 +01:00
Fabian Homborg
57d23c390b docs: Reword argparse a bit
In particular use "variable" instead of "var".
2021-01-01 14:03:00 +01:00
Fabian Homborg
7ea8e20623
argparse: Make short flag names optional (#7585)
It was always a bit ridiculous that argparse required `X-longflag` if
that "X" short flag was never actually used anywhere.

Since the short letter is for getopt's benefit, we can hack around
this with our old friend: Unicode Private Use Areas.

We have a counter, starting at 0xE000 and going to 0xF8FF, that counts
up for all options that don't have a short flag and provides one. This
gives us up to 6400 long-only options.

6.4K should be enough for everybody.
2021-01-01 11:37:25 +01:00
Marcus Atilius Regulus
7b9c1a6076 escape a backslash (in 2 places) in argparse docs 2020-11-13 14:27:12 +01:00
Johannes Altmanninger
4081d58577 docs: use monospace for inline code snippets more consistently 2020-10-26 19:25:41 +01:00
Charles Gould
f73ee30111 docs: Fix markup for code blocks 2020-10-10 21:49:33 +02:00
Fabian Homborg
0eeaa796fd docs: Fix argparse chapter
Missing a label.

Oops.

[ci skip]
2020-10-08 17:35:29 +02:00
Fabian Homborg
392b61014b docs: Some more argparse rewordings
[ci skip]
2020-10-07 21:52:35 +02:00
Fabian Homborg
547f649797 docs: Slight reword of argparse's optional argument section
[ci skip]
2020-06-17 15:36:50 +02:00
Fabian Homborg
5efe1a09ce docs/argparse: Add note on optional arguments
Yeah I had to answer this one again.

[ci skip]
2020-06-04 17:28:02 +02:00
fcd
3246f736b8 docs: Fix repeated word in argparse documentation 2020-03-25 18:23:19 +01:00
Fabian Homborg
bfc1de9ef4 argparse: Pass validation variables as exported
This was written before local-exported variables did anything useful.

Passing these vars as local-exports removes the need to define the
validation function with `--no-scope-shadowing` which is quite the
hack.
2020-03-01 19:28:51 +01:00
Aaron Gyes
85a0ca66e0 We no longer have two doc systems, move sphinx_doc_src back to doc_src 2020-02-19 17:00:35 -08:00