-
Notifications
You must be signed in to change notification settings - Fork 79
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
6 changed files
with
74 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE Arrows #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE QuasiQuotes #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TupleSections #-} | ||
{-# LANGUAGE ViewPatterns #-} | ||
|
||
module Niv.Local.Cmd where | ||
|
||
import Niv.Cmd | ||
import Control.Arrow | ||
import Niv.Sources | ||
import Niv.Update | ||
import qualified Data.Aeson as Aeson | ||
import qualified Data.HashMap.Strict as HMS | ||
import qualified Data.Text as T | ||
import qualified Options.Applicative as Opts | ||
import qualified Options.Applicative.Help.Pretty as Opts | ||
|
||
localCmd :: Cmd | ||
localCmd = Cmd | ||
{ description = describeLocal | ||
, parseCmdShortcut = parseLocalShortcut | ||
, parsePackageSpec = parseLocalPackageSpec | ||
, updateCmd = proc () -> do | ||
useOrSet "type" -< ("local" :: Box T.Text) | ||
returnA -< () | ||
, name = "local" | ||
} | ||
|
||
parseLocalShortcut :: T.Text -> Maybe (PackageName, Aeson.Object) | ||
parseLocalShortcut txt = | ||
if (T.isPrefixOf "./" txt || T.isPrefixOf "/" txt ) then do | ||
let n = last $ T.splitOn "/" txt | ||
Just (PackageName n, HMS.fromList [ ("path", Aeson.String txt) ]) | ||
else Nothing | ||
|
||
parseLocalPackageSpec :: Opts.Parser PackageSpec | ||
parseLocalPackageSpec = PackageSpec . HMS.fromList <$> parseParams | ||
where | ||
parseParams :: Opts.Parser [(T.Text, Aeson.Value)] | ||
parseParams = maybe [] pure <$> Opts.optional parsePath | ||
|
||
parsePath = | ||
("path", ) . Aeson.String <$> Opts.strOption | ||
( Opts.long "path" <> | ||
Opts.metavar "PATH" | ||
) | ||
|
||
describeLocal :: Opts.InfoMod a | ||
describeLocal = mconcat | ||
[ Opts.fullDesc | ||
, Opts.progDesc "Add a local dependency. Experimental." | ||
, Opts.headerDoc $ Just $ | ||
"Examples:" Opts.<$$> | ||
"" Opts.<$$> | ||
" niv add local ./foo/bar" | ||
] |
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