summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2025-03-19 20:15:25 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2025-03-19 20:49:47 +0100
commit78303c0327d2c0fd60f1399df11d49b54c1101e4 (patch)
treef95778856192adeb196ea84020fa8315d2840c5c
parent875ddfe8c9c42861d9c8876b14b95e05b4ae0fd9 (diff)
NonEmpty list of commands to avoid partial head
-rw-r--r--src/Main.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Main.hs b/src/Main.hs
index b98c66a..22ce236 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -6,6 +6,7 @@ import Control.Monad.Reader
import Data.ByteString.Lazy qualified as BL
import Data.List
+import Data.List.NonEmpty qualified as NE
import Data.Proxy
import Data.Text qualified as T
@@ -63,10 +64,10 @@ options =
data SomeCommandType = forall c. Command c => SC (Proxy c)
-commands :: [ SomeCommandType ]
+commands :: NE.NonEmpty SomeCommandType
commands =
- [ SC $ Proxy @RunCommand
- , SC $ Proxy @CheckoutCommand
+ ( SC $ Proxy @RunCommand) NE.:|
+ [ SC $ Proxy @CheckoutCommand
]
lookupCommand :: String -> Maybe SomeCommandType
@@ -105,12 +106,12 @@ main = do
padTo n str = str <> replicate (n - length str) ' '
padCommand = padTo (maxCommandNameLength + 3)
commandNameLength (SC proxy) = length $ commandName proxy
- maxCommandNameLength = maximum $ map commandNameLength commands
+ maxCommandNameLength = maximum $ fmap commandNameLength commands
putStr $ usageInfo header options <> unlines (
[ ""
, "Available commands:"
- ] ++ map commandDesc commands
+ ] ++ map commandDesc (NE.toList commands)
)
exitSuccess
@@ -127,7 +128,7 @@ main = do
_ -> ( , cmdargs ) <$> findConfig
( ncmd, cargs ) <- case cmdargs' of
- [] -> return ( head commands, [] )
+ [] -> return ( NE.head commands, [] )
(cname : cargs)
| Just nc <- lookupCommand cname -> return (nc, cargs)