Skip to content

Instantly share code, notes, and snippets.

@0rca
Created January 6, 2017 11:16
Show Gist options
  • Save 0rca/f35ee97e5804b87c14114df852a8c00f to your computer and use it in GitHub Desktop.
Save 0rca/f35ee97e5804b87c14114df852a8c00f to your computer and use it in GitHub Desktop.
cli tool in Haskell
#!/usr/bin/env stack --silent runhaskell
{-# LANGUAGE OverloadedStrings #-}
import Console.Options
import Turtle
import Data.Text hiding (empty)
main = defaultMain $ do
programName "cli"
programDescription "personal CLI utilities"
command "help" $ do
action $ \_ -> do
echo "Usage: cli [command] [arguments]"
echo ""
echo "Available commands:"
echo " posgres start/stop posgresql server"
echo " version prints version"
echo ""
command "version" $ do
action $ \_ -> do
echo "cli version 0.0.1"
command "postgres" $ do
command "start" $
action $ \toParam -> do
code <- shell "tmux new-session -d -s \"postgresql\" -n posgres-server postgres -D /usr/local/var/postgres" empty
guard (code == ExitSuccess)
echo "started"
command "stop" $
action $ \toParam -> do
shell "tmux send-keys -t \"postgresql\" C-c C-d" empty
echo "stopped"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment