diff --git a/CHANGELOG.md b/CHANGELOG.md index 7429a21..d5c5851 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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][]) diff --git a/README.md b/README.md index 90c7e84..5000aba 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/NixTree/App.hs b/src/NixTree/App.hs index 9c34ba8..63cb01b 100644 --- a/src/NixTree/App.hs +++ b/src/NixTree/App.hs @@ -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 diff --git a/src/NixTree/Main.hs b/src/NixTree/Main.hs index 11e2a3f..1f3d3b8 100644 --- a/src/NixTree/Main.hs +++ b/src/NixTree/Main.hs @@ -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