Skip to content

Commit 45eb61e

Browse files
authored
Merge pull request #8 from justinwoo/version
add version command
2 parents b7d423a + 8050604 commit 45eb61e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

app/Main.hs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
module Main where
44

5+
import qualified Data.Text as Text
6+
import Data.Version (showVersion)
7+
import qualified Paths_spacchetti_cli as Pcli
58
import qualified Turtle as T
69

710
-- | Commands that this program handles
@@ -18,6 +21,8 @@ data Command
1821
-- | echo wrote packages.json to $TARGET
1922
-- | ```
2023
| InsDhall
24+
-- | Show spacchetti-cli version
25+
| Version
2126

2227
insDhall :: IO ()
2328
insDhall = do
@@ -72,20 +77,27 @@ localSetup force = do
7277
pscPackageJsonTemplate = "{\"name\": \"my-project\", \"set\": \"local\", \"source\": \"\", \"depends\": []}"
7378
packagesDhallTemplate = "let mkPackage = https://raw.githubusercontent.com/justinwoo/spacchetti/140918/src/mkPackage.dhall in let upstream = https://raw.githubusercontent.com/justinwoo/spacchetti/140918/src/packages.dhall in upstream"
7479

80+
printVersion :: IO ()
81+
printVersion =
82+
T.echo $ T.unsafeTextToLine (Text.pack $ showVersion Pcli.version)
83+
7584
parser :: T.Parser Command
7685
parser
7786
= LocalSetup <$> localSetup
7887
T.<|> InsDhall <$ insDhall
88+
T.<|> Version <$ version
7989
where
8090
localSetup =
8191
T.subcommand
8292
"local-setup" "run project-local Spacchetti setup" $
8393
T.switch "force" 'f' "Overwrite any project found in the current directory."
8494
insDhall = T.subcommand "insdhall" "insdhall the local package set" $ pure ()
95+
version = T.subcommand "version" "Show spacchetti-cli version" $ pure ()
8596

8697
main :: IO ()
8798
main = do
88-
options <- T.options "Spacchetti CLI" parser
89-
case options of
99+
command <- T.options "Spacchetti CLI" parser
100+
case command of
90101
LocalSetup force -> localSetup force
91-
InsDhall -> insDhall
102+
InsDhall -> insDhall
103+
Version -> printVersion

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ description: Please see the README on GitHub at <https://github.com/gith
2121

2222
dependencies:
2323
- base >= 4.7 && < 5
24+
- text < 1.3
2425
- turtle
2526

2627
executables:

0 commit comments

Comments
 (0)