From ac7a377c9762f095dc8286d3dc0b4b5af8c3216c Mon Sep 17 00:00:00 2001 From: Daniel Rolls Date: Sat, 22 Feb 2025 09:43:41 +0000 Subject: [PATCH] Fix some exit codes & help text --- CHANGELOG.md | 3 +++ src/Constants.hs | 10 +++++----- src/Shellify.hs | 6 +++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index effbc9f..947cd73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog for Shellify +## Next Release +- Return exit code zero when some invalid options are passed + ## 0.12.0 - Add --allow-local-pinned-registries-to-be-prioritized switch - Prioiritise registries favouring those not pinned to local diff --git a/src/Constants.hs b/src/Constants.hs index f15ee4f..412ddc7 100644 --- a/src/Constants.hs +++ b/src/Constants.hs @@ -4,11 +4,11 @@ import Data.Text (Text()) import Text.RawString.QQ (r) helpText :: Text -> Text -helpText progName = "USAGE: " <> progName <> [r| -p [PACKAGES] - |] <> progName <> [r| [--with-flakes] [PACKAGES] +helpText progName = "USAGE: " <> progName <> [r| -p [PACKAGES] [--with-flakes] + |] <> progName <> [r| shell [PACKAGES] Pass nix-shell arguments to nix-shellify to have it generate a shell.nix in -the current directory. You can then just run nix shell or nix-shell in that +the current directory. You can then just run nix develop or nix-shell in that directory to have those packages in your environment. To run nix commands you must first install Nix. @@ -21,8 +21,8 @@ Options Command to run after creating the shell --with-flake - When using the command in a flake-like style use this switch to have a - flake.nix created in addition to a shell.nix. Highly recommended to ensure + When using the -p option to specify packages, use this switch to have a + flake.nix created in addition to a shell.nix. This is recommended to ensure the versions of dependencies are kept for reproducibility and so that shells are cached to load faster. diff --git a/src/Shellify.hs b/src/Shellify.hs index 92edbde..8c84a8d 100644 --- a/src/Shellify.hs +++ b/src/Shellify.hs @@ -25,8 +25,8 @@ createAFile (name, content) = do extCde <- createFile (unpack name) content runShellify :: [Text] -> IO () runShellify(pName:args) = getRegistryDB >>= either - ((printErrorAndReturnFailure . ("Error calling nix registry: " <>) ) >=> exitWith) - (\registryDB -> either printError + (printErrorAndReturnFailure . ("Error calling nix registry: " <>)) + (\registryDB -> either printErrorAndReturnFailure (mapM_ createAFile) $ parseOptionsAndCalculateExpectedFiles registryDB pName args) @@ -66,6 +66,6 @@ returnCode _ _ = ExitFailure 1 shouldGenerateNewFile :: Maybe Text -> Bool shouldGenerateNewFile = (== Nothing) -printErrorAndReturnFailure err = printError err >> return (ExitFailure 1) +printErrorAndReturnFailure err = printError err >> exitWith (ExitFailure 1) printError = hPutStrLn stderr