Skip to content

Commit

Permalink
Fix juvix init (#1835)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira authored Feb 10, 2023
1 parent d15a569 commit f897fc2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
13 changes: 7 additions & 6 deletions app/Commands/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ checkNotInProject =
say "You are already in a Juvix project"
embed exitFailure

getPackage :: forall r. (Members '[Embed IO] r) => Sem r Package
getPackage :: forall r. Members '[Embed IO] r => Sem r Package
getPackage = do
tproj <- getProjName
say "Tell me the version of your project [leave empty for 0.0.0]"
say "Write the version of your project [leave empty for 0.0.0]"
root <- getCurrentDir
let pkg = defaultPackage root (rootBuildDir root)
tversion :: SemVer <- getVersion
return
Package
pkg
{ _packageName = tproj,
_packageVersion = Ideal tversion,
_packageDependencies = mempty
_packageVersion = Ideal tversion
}

getProjName :: forall r. (Members '[Embed IO] r) => Sem r Text
Expand All @@ -59,7 +60,7 @@ getProjName = do
Nothing -> mempty
Just d' -> " [leave empty for '" <> d' <> "']"
say
( "Tell me the name of your project"
( "Write the name of your project"
<> defMsg
<> " (lower case letters, numbers and dashes are allowed): "
)
Expand Down
21 changes: 11 additions & 10 deletions src/Juvix/Compiler/Pipeline/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Juvix.Compiler.Pipeline.Package
)
where

import Data.Aeson (genericToEncoding)
import Data.Aeson (genericToEncoding, genericToJSON)
import Data.Aeson.BetterErrors
import Data.Aeson.TH
import Data.Kind qualified as GHC
Expand Down Expand Up @@ -61,15 +61,16 @@ deriving stock instance Show RawPackage

deriving stock instance Show Package

rawPackageOptions :: Options
rawPackageOptions =
defaultOptions
{ fieldLabelModifier = over Lens._head toLower . dropPrefix "_package",
rejectUnknownFields = True
}

instance ToJSON RawPackage where
toEncoding = genericToEncoding options
where
options :: Options
options =
defaultOptions
{ fieldLabelModifier = over Lens._head toLower . dropPrefix "_package",
rejectUnknownFields = True
}
toJSON = genericToJSON rawPackageOptions
toEncoding = genericToEncoding rawPackageOptions

-- | TODO: is it a good idea to return the empty package if it fails to parse?
instance FromJSON RawPackage where
Expand All @@ -93,7 +94,7 @@ rawDefaultPackage =

-- | Has the implicit stdlib dependency
defaultPackage :: Path Abs Dir -> Path Abs Dir -> Package
defaultPackage r buildDir = fromRight impossible . run . runError @Text . processPackage r buildDir $ rawDefaultPackage
defaultPackage root buildDir = fromRight impossible . run . runError @Text . processPackage root buildDir $ rawDefaultPackage

-- | Has no dependencies
emptyPackage :: Package
Expand Down
1 change: 1 addition & 0 deletions src/Juvix/Compiler/Pipeline/Package/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ deriving stock instance Show RawDependency
deriving stock instance Show Dependency

instance ToJSON RawDependency where
toJSON (Dependency p) = toJSON (fromSomeDir p)
toEncoding (Dependency p) = toEncoding (fromSomeDir p)

instance FromJSON RawDependency where
Expand Down
19 changes: 19 additions & 0 deletions tests/smoke/Commands/init.smoke.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
working-directory: ./../../../tests/

tests:
- name: init
command:
shell:
- bash
script: |
mkdir tmp
cd tmp
juvix init
cat juvix.yaml
cd ..
rm -rf tmp
stdout:
contains:
"name: tmp"
stdin: "\n\n"
exit-status: 0

0 comments on commit f897fc2

Please sign in to comment.