-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
171 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,50 @@ | ||
module FlakeIt.Cli where | ||
|
||
import Data.List qualified as List | ||
import Data.Text qualified as Text | ||
import Data.Text.IO qualified as TIO | ||
import Data.Version (Version, showVersion) | ||
import FlakeIt.Cli.Parser | ||
import FlakeIt.DB qualified as DB | ||
import FlakeIt.Nix qualified as Nix | ||
import FlakeIt.Template | ||
import FlakeIt.Types | ||
import Options.Applicative | ||
import Options.Applicative (execParser) | ||
import Paths_flakeit qualified as Meta (version) | ||
import System.Exit (exitFailure) | ||
import System.IO (stderr) | ||
|
||
flakeit :: Version -> (Command -> IO ()) -> IO () | ||
flakeit version performCommand = execParser (cliParser version) >>= performCommand | ||
|
||
flakeitCli :: IO () | ||
flakeitCli = flakeit Meta.version runCliCommand | ||
|
||
addTemplateGroup :: TemplateUrl -> IO () | ||
addTemplateGroup url = do | ||
maybeTemplates <- Nix.getTemplateGroup url | ||
case maybeTemplates of | ||
Just ts -> DB.add ts | ||
Nothing -> error "Could not find templates..." | ||
runCliCommand :: Command -> IO () | ||
runCliCommand = \case | ||
List opts -> runList opts | ||
Add opts -> runAdd opts | ||
Remove opts -> runRemove opts | ||
New opts -> runNew opts | ||
Init opts -> runInit opts | ||
|
||
runList :: ListOptions -> IO () | ||
runList opts = do | ||
db <- DB.getAll | ||
TIO.putStr $ prettyTemplates db | ||
|
||
runAdd :: AddOptions -> IO () | ||
runAdd opts = addTemplateGroup opts.path | ||
|
||
runUpdate :: UpdateOptions -> IO () | ||
runUpdate opts = addTemplateGroup opts.path | ||
runAdd opts = do | ||
maybeSource <- Nix.getTemplateSource opts.url | ||
case maybeSource of | ||
Just source -> DB.add source | ||
Nothing -> do | ||
TIO.hPutStrLn stderr "error: Could not parse the flake" | ||
exitFailure | ||
|
||
runRemove :: RemoveOptions -> IO () | ||
runRemove opts = DB.remove opts.path | ||
runRemove opts = DB.remove opts.url | ||
|
||
runNew :: NewOptions -> IO () | ||
runNew opts = Nix.newTemplate opts.name opts.template | ||
runNew opts = Nix.newTemplate opts.projectName opts.template | ||
|
||
runInit :: InitOptions -> IO () | ||
runInit opts = Nix.initTemplate opts.template | ||
|
||
runCliCommand :: Command -> IO () | ||
runCliCommand = \case | ||
List opts -> runList opts | ||
Add opts -> runAdd opts | ||
Update opts -> runUpdate opts | ||
Remove opts -> runRemove opts | ||
New opts -> runNew opts | ||
Init opts -> runInit opts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.