Improve help text

This commit is contained in:
Utku Demir 2022-11-19 15:42:28 +13:00
parent e5ad1b714a
commit e43184a3b5
4 changed files with 42 additions and 26 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## Unreleased
* feat: Improved help text.
## 0.2.1 - 2022-10-24:
* fix: Fix excessive memory use when using why-depends on large dependency graphs (issue: [@31][])

View File

@ -31,8 +31,17 @@ nix run github:utdemir/nix-tree
```
$ nix-tree --help
Usage: nix-tree [paths...] [-h|--help] [--version]
Paths default to $HOME/.nix-profile and /var/run/current-system.
Usage: nix-tree [--version] [--derivation] [INSTALLABLE]
Interactively browse dependency graphs of Nix derivations.
Available options:
--version Show the nix-tree version.
--derivation Operate on the store derivation rather than its
outputs.
INSTALLABLE A store path or a flake reference. Paths default to
"~/.nix-profile" and "/var/run/current-system".
-h,--help Show this help text
Keybindings:
hjkl/Arrow Keys : Navigate
w : Open why-depends mode
@ -40,7 +49,7 @@ Keybindings:
s : Change sort order
y : Yank selected path to clipboard
? : Show help
q/Esc: : Quit / close modal
q/Esc : Quit / close modal
```
### Glossary

View File

@ -407,12 +407,12 @@ helpText =
T.intercalate
"\n"
[ "hjkl/Arrow Keys : Navigate",
"w : Open why-depends mode",
"/ : Open search mode",
"w : Open why-depends modal",
"/ : Open search modal",
"s : Change sort order",
"y : Yank selected path to clipboard",
"? : Show help",
"q/Esc: : Quit / close modal"
"q/Esc : Quit / close modal"
]
helpNotice :: Notice

View File

@ -7,19 +7,20 @@ import Control.Exception (evaluate)
import NixTree.App
import NixTree.PathStats
import qualified Options.Applicative as Opts
import qualified Options.Applicative.Help.Pretty as Opts
import System.Directory (doesDirectoryExist, getHomeDirectory)
import System.Exit (ExitCode (..))
import System.FilePath ((</>))
import System.IO (hPutStr, hPutStrLn)
import System.IO (hPutStrLn)
import System.ProgressBar hiding (msg)
version :: Text
version = VERSION_nix_tree
data Opts = Opts
{ oVersion :: Bool,
oDerivation :: Bool,
oInstallables :: [Installable]
{ oInstallables :: [Installable],
oVersion :: Bool,
oDerivation :: Bool
}
optsParser :: Opts.ParserInfo Opts
@ -27,29 +28,31 @@ optsParser =
Opts.info (parser <**> Opts.helper) $
mconcat
[ Opts.progDesc "Interactively browse dependency graphs of Nix derivations.",
Opts.fullDesc
Opts.fullDesc,
Opts.footerDoc (Just keybindingsHelp)
]
where
parser :: Opts.Parser Opts
parser =
Opts
<$> Opts.switch (Opts.long "version" <> Opts.help "Show the nix-tree version.")
<*> Opts.switch (Opts.long "derivation" <> Opts.help "Operate on the store derivation rather than its outputs.")
<*> many (Opts.strArgument @Text (Opts.metavar "INSTALLABLE" <> Opts.help "A store path or a flake reference.") <&> Installable)
<$> many
( Installable
<$> Opts.strArgument @Text
( Opts.metavar "INSTALLABLE"
<> Opts.help "A store path or a flake reference. Paths default to \"~/.nix-profile\" and \"/var/run/current-system\""
)
)
<*> Opts.switch (Opts.long "version" <> Opts.help "Show the nix-tree version")
<*> Opts.switch (Opts.long "derivation" <> Opts.help "Operate on the store derivation rather than its outputs")
usage :: Text
usage =
unlines
[ "Usage: nix-tree [paths...] [-h|--help] [--version]",
" Paths default to $HOME/.nix-profile and /var/run/current-system.",
"Keybindings:",
unlines . map (" " <>) . lines $ helpText
]
keybindingsHelp :: Opts.Doc
keybindingsHelp =
"Keybindings:"
Opts.<$$> (Opts.indent 2 . Opts.vsep $ map (Opts.text . toString) (lines helpText))
usageAndFail :: Text -> IO a
usageAndFail msg = do
showAndFail :: Text -> IO a
showAndFail msg = do
hPutStrLn stderr . toString $ "Error: " <> msg
hPutStr stderr $ toString usage
exitWith (ExitFailure 1)
main :: IO ()
@ -72,7 +75,7 @@ main = do
"/var/run/current-system"
]
case roots of
[] -> usageAndFail "No store path given."
[] -> showAndFail "No store path given."
p : ps -> return . fmap (Installable . toText) $ p :| ps
withStoreEnv (opts & oDerivation) installables $ \env' -> do