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

cabal man does not work on macOS #7714

Closed
andreasabel opened this issue Oct 7, 2021 · 11 comments · Fixed by #7726
Closed

cabal man does not work on macOS #7714

andreasabel opened this issue Oct 7, 2021 · 11 comments · Fixed by #7726

Comments

@andreasabel
Copy link
Member

Re #6548:

cabal man does not work on macOS

$ cabal man 
man: invalid option -- l
man, version 1.6c

usage: man [-adfhktwW] [section] [-M path] [-P pager] [-S list]
	[-m system] [-p string] name ...

  a : find all matching entries
...
fd:13: commitBuffer: resource vanished (Broken pipe)

Also, there is a typo in an error message:

$ cabal man happy
Error: cabal: 'manpage' doesn't take any extra arguments: happy
@andreasabel
Copy link
Member Author

Something that might be more portable is piping into groff:

$ cabal man --raw | groff -Tutf8 -i | less

(That looks horrible. But even the HTML rendering is horrible.)

However, the output of cabal man is not well-formatted, it seems:

$ cabal man --raw | groff -Tutf8 -i > /dev/null 2> man-errors.txt
$ cat man-errors.txt 
<standard input>:3825: warning: macro `new-repl'' not defined (probably missing space after `ne')
<standard input>:20376: warning: macro `new-build',' not defined (probably missing space after `ne')
<standard input>:20381: warning: macro `new-build' not defined (probably missing space after `ne')

Quick fix is to drop the piping into man part and make --raw the default.

Then folks can choose their OS-specific rendering of their taste.

@fgaz
Copy link
Member

fgaz commented Oct 7, 2021

Is there any way to make man read a page from stdin (or at least from a file) on macos? does cabal man --raw | man /dev/stdin work? what about cabal man --raw > temporary_file && man temporary_file? I guess no due to the groff error?

@gbaz
Copy link
Collaborator

gbaz commented Oct 7, 2021

What about using nroff instead of groff as in https://unix.stackexchange.com/a/313110 ?

@andreasabel
Copy link
Member Author

Here is man's man page for BSD: https://www.freebsd.org/cgi/man.cgi?query=man

@fgaz wrote:

does cabal man --raw | man /dev/stdin work?

Thanks indeed, this works, yet without formatting.

However, this is of limited use because:

$ cabal man --raw | wc
   54621  126439  871117

cabal man produces a 50kloc text! Not sure that this meets the intuitive expectations of a man page.

It seems like every option is repeated for each command. The text is highly redundant:

$ cabal man --raw | sort | uniq | wc
    1385    7760   56194

So, it is inflated by a factor of >30.

What is actually the purpose of cabal man? Dump the whole help text rather than exploring it via the --help flag?

Is it used to automatically produce man-pages for some distro?

@gbaz wrote:

What about using nroff instead of groff as in unix.stackexchange.com/a/313110 ?

Thanks, this actually produces nice formatting.

$ cabal man --raw | nroff -man /dev/stdin | less

It still suffers from the redundancy problem, though.

@andreasabel andreasabel self-assigned this Oct 8, 2021
andreasabel added a commit to andreasabel/cabal that referenced this issue Oct 8, 2021
WIP: This does not work yet, I need some help with constructing the
pipe correctly in Haskell.
@andreasabel
Copy link
Member Author

See #7714: I am trying to implement a pipe in Haskell to the effect of

$ cabal man --raw | nroff -man /dev/stdin | less

but for some reason it does not do what I would expect. Help wanted!

@fgaz
Copy link
Member

fgaz commented Oct 8, 2021

We have to keep in mind that nroff/groff could be absent too! For example in NixOS:

$ cabal man --raw | nroff -man /dev/stdin
The program 'nroff' is not in your PATH. You can make it available in an
ephemeral shell by typing:
  nix-shell -p groff

Should the command depend on the platform?

Furthermore, less may not be the user's $PAGER

@gbaz
Copy link
Collaborator

gbaz commented Oct 8, 2021

I think this is a lot of hoops to jump through for a rarely used command that doesn't seem particularly important for most purposes? I'm in favor of doing a basic fix to it, but unless we already have infrastructure in place to lookup a pager etc, probably overkill.

@fgaz
Copy link
Member

fgaz commented Oct 9, 2021

Oh for sure, I just meant that the fix shouldn't be at the expense of other users, like in linux, where man is ubiquitous and respects $PAGER, but groff isn't as much.

I wasn't actually proposing to check for $PAGER, just to case on the platform, which would be strictly an improvement for all users. The pager issue was an argument for keeping man where possible.

edit: well ok, nroff is actually a dependency of man, it's just that NixOS doesn't expose dependencies by default, which isn't what the majority does. So I guess this affects less platforms than I thought, and only the $PAGER regression remains, which is minor compared to making the command work on all platforms

@andreasabel
Copy link
Member Author

The output of cabal man --raw is producing the following problems when piped into nroff -man:

  • The sequence 'ne, if placed a the beginning of a line, seems to invoke a macro:
    cabal.man:3825: warning: macro `new-repl'' not defined (probably missing space after `ne')
    
    This happens when quotes like 'new-repl' etc. end up at the beginning of the line by chance.
    A fix is to not have a line break before 'ne, but this is maybe not so obvious how to realize this.
  • Problems with .R:
    `R' is a string (producing the registered sign), not a macro.
    
    According to man node produces warnings on macOS nodejs/node#18434 (comment) the prefix .R is superfluous ("pretty silly") and can be deleted. This removes the warnings.

andreasabel added a commit to andreasabel/cabal that referenced this issue Oct 12, 2021
Directly piping into `man -l -` does not work as BSD-`man` does not
understand option `-l`.  More standardized are the building blocks
`nroff` and `less`.

`cabal man` now should behave as pipeline
```
cabal man --raw | nroff -man /dev/stdin | less
```

Also fixed output of `cabal man --raw` so that it does not produce
warnings.

- `.R` removed.  Was warning:
  ```
  `R' is a string (producing the registered sign), not a macro.
  ```

- No quoted 'new-FOO' should appear at beginning of line.  Was
  warning:
  ```
  warning: macro `new-FOO'' not defined (probably missing space after `ne')
  ```

Added to `cabal-testsuite/PackageTests/Man/cabal.test.hs` a check that
the `stderr` output of `nroff -man /dev/stdin` is empty (no warnings).

Remaining problem:

Unfortunately, after quitting `less` with `q` the following error is
displayed:
```
fd:NNN: commitBuffer: resource vanished (Broken pipe)
```
Not sure how to fix this (my attempts failed).
andreasabel added a commit to andreasabel/cabal that referenced this issue Oct 12, 2021
andreasabel added a commit to andreasabel/cabal that referenced this issue Oct 12, 2021
andreasabel added a commit to andreasabel/cabal that referenced this issue Oct 12, 2021
…Windows

Windows does not have `nroff` (neither has it `man`) and `cabal man`
fails there usually for lack of these backends.
@hasufell
Copy link
Member

apparently, this also happens on BSD

@fgaz
Copy link
Member

fgaz commented Jan 19, 2022

@hasufell feel free to review #7726 ;)

andreasabel added a commit to andreasabel/cabal that referenced this issue Jan 20, 2022
Directly piping into `man -l -` does not work as BSD-`man` does not
understand option `-l`.  More standardized are the building blocks
`nroff` and `less`.

`cabal man` now should behave as pipeline
```
cabal man --raw | nroff -man /dev/stdin | less
```

Also fixed output of `cabal man --raw` so that it does not produce
warnings.

- `.R` removed.  Was warning:
  ```
  `R' is a string (producing the registered sign), not a macro.
  ```

- No quoted 'new-FOO' should appear at beginning of line.  Was
  warning:
  ```
  warning: macro `new-FOO'' not defined (probably missing space after `ne')
  ```

Added to `cabal-testsuite/PackageTests/Man/cabal.test.hs` a check that
the `stderr` output of `nroff -man /dev/stdin` is empty (no warnings).

Remaining problem:

Unfortunately, after quitting `less` with `q` the following error is
displayed:
```
fd:NNN: commitBuffer: resource vanished (Broken pipe)
```
Not sure how to fix this (my attempts failed).
andreasabel added a commit to andreasabel/cabal that referenced this issue Jan 20, 2022
andreasabel added a commit to andreasabel/cabal that referenced this issue Jan 20, 2022
andreasabel added a commit to andreasabel/cabal that referenced this issue Jan 20, 2022
…Windows

Windows does not have `nroff` (neither has it `man`) and `cabal man`
fails there usually for lack of these backends.
andreasabel added a commit that referenced this issue Jan 21, 2022
Fix #7714: use nroff -man | less as backend for cabal man
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment