wjt / bustle

Someone's favourite D-Bus profiler (mirror)
https://gitlab.freedesktop.org/bustle/bustle
Other
8 stars 3 forks source link

Support for `help2man` #2

Open taktoa opened 8 years ago

taktoa commented 8 years ago

I noticed that you generate a man page for bustle-pcap with help2man. It seems like it would be better if we could have bustle output its help in a way that also allows use of help2man (even if it's too painful to get the build system to run it, some distributions, like NixOS, can make use of this). As it stands, there are two problems:

  1. There is no --version flag on bustle. This should be quite helpful for implementing that in a maintainable way.
  2. The format of the --help output is not quite right.

Here's a bash script that has fairly appealing behavior when run under help2man:

#!/usr/bin/env bash

if [[ "${1}" = "--help" ]]; then
    cat <<EOF
Usage: bustle [LOG [...]]
   or: bustle --pair SESSION_LOG SYSTEM_LOG
   or: bustle (--count|--time|--dot) LOG

Bustle draws sequence diagrams of D-Bus activity, showing signal emissions,
method calls and their corresponding returns, with timestamps for each
individual event and the duration of each method call. This can help you check
for unwanted D-Bus traffic, and pinpoint why your D-Bus-based application isn't
performing as well as you like. It also provides statistics like signal
frequencies and average method call times.

The \`bustle-pcap' executable, if available, allows for the offline generation
of log files, which can later be inspected with Bustle.

Help Options:
  -h, --help        Show help options

Application Options:
      --pair        Load a pair of log files: one recorded from the session bus,
                    and one recorded from the system bus.
      --count       Print count statistics for the given LOG.
      --time        Print time statistics for the given LOG.
      --dot         Print a Graphviz-style message graph for the given LOG.
  -V, --version     Print version information and exit

EOF
elif [[ "${1}" = "--version" ]]; then
    cat <<EOF
bustle 0.5.4

Copyright 2011 Will Thompson <will@willthompson.co.uk>
This is free software; see the source for copying conditions.  There is NO \
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Written by Will Thompson <will@willthompson.co.uk>
EOF
fi
taktoa commented 8 years ago

It's also worth noting that you could probably get a lot of this functionality for free by switching to a proper argument parsing library. I'm partial to docopt, but optparse-applicative and cmdargs are supposed to be pretty good as well (some of them allow for automatic generation of bash completion scripts, which is always nice).

wjt commented 8 years ago

I can't decide if docopt sounds great or scary. 😄 Using optparse-applicative and cmdargs might be a bit kinder to distro packagers in any case: Debian and Fedora both package both of those, but neither packages the Haskell version of docopt.

I'm don't have time to work on this at the moment, but a patch would be very welcome!