-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Moved cmdParserInfo to separate file. Moved envSettings to separate file. Created initial and failing test for testing help * getting somewhere * Added help tests * Reverted main * Renamed function * Fixes #56 along with PR 68 comments * Renamed cmd to internal
- Loading branch information
1 parent
0b9c50d
commit 1bede5f
Showing
10 changed files
with
236 additions
and
83 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,30 @@ | ||
{- | | ||
Module : Iris.Cli.Cmd | ||
Copyright : (c) 2022 Dmitrii Kovanikov | ||
SPDX-License-Identifier : MPL-2.0 | ||
Maintainer : Dmitrii Kovanikov <[email protected]> | ||
Stability : Experimental | ||
Portability : Portable | ||
Wrapper around cmd. | ||
@since x.x.x.x | ||
-} | ||
|
||
module Iris.Cli.Internal | ||
( | ||
Cmd (..) | ||
) where | ||
|
||
import Data.Kind (Type) | ||
import Iris.Cli.Interactive (InteractiveMode) | ||
|
||
{- | | ||
Wrapper around @cmd@ with additional predefined fields | ||
-} | ||
|
||
data Cmd (cmd :: Type) = Cmd | ||
{ cmdInteractiveMode :: InteractiveMode | ||
, cmdCmd :: cmd | ||
} |
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,48 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE ApplicativeDo #-} | ||
|
||
{- | | ||
Module : Iris.Cli.ParserInfo | ||
Copyright : (c) 2022 Dmitrii Kovanikov | ||
SPDX-License-Identifier : MPL-2.0 | ||
Maintainer : Dmitrii Kovanikov <[email protected]> | ||
Stability : Experimental | ||
Portability : Portable | ||
Parser information for the default CLI parser. | ||
@since 0.0.0.0 | ||
-} | ||
|
||
module Iris.Cli.ParserInfo (cmdParserInfo) where | ||
|
||
import Iris.Cli.Internal ( Cmd (..) ) | ||
import Iris.Cli.Interactive (interactiveModeP) | ||
import Iris.Settings (CliEnvSettings (..)) | ||
import Iris.Cli.Version (mkVersionParser) | ||
|
||
import qualified Options.Applicative as Opt | ||
|
||
{- | | ||
@since 0.0.0.0 | ||
-} | ||
|
||
cmdParserInfo :: forall cmd appEnv . CliEnvSettings cmd appEnv -> Opt.ParserInfo (Cmd cmd) | ||
cmdParserInfo CliEnvSettings{..} = Opt.info | ||
( Opt.helper | ||
<*> mkVersionParser cliEnvSettingsVersionSettings | ||
<*> cmdP | ||
) | ||
$ mconcat | ||
[ Opt.fullDesc | ||
, Opt.header cliEnvSettingsHeaderDesc | ||
, Opt.progDesc cliEnvSettingsProgDesc | ||
] | ||
where | ||
cmdP :: Opt.Parser (Cmd cmd) | ||
cmdP = do | ||
cmdInteractiveMode <- interactiveModeP | ||
cmdCmd <- cliEnvSettingsCmdParser | ||
|
||
pure Cmd{..} |
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,63 @@ | ||
{- | | ||
Module : Iris.Settings | ||
Copyright : (c) 2022 Dmitrii Kovanikov | ||
SPDX-License-Identifier : MPL-2.0 | ||
Maintainer : Dmitrii Kovanikov <[email protected]> | ||
Stability : Experimental | ||
Portability : Portable | ||
Settings of a CLI app environment. | ||
@since x.x.x.x | ||
-} | ||
|
||
|
||
module Iris.Settings | ||
( -- * Settings for the CLI app | ||
CliEnvSettings (..) | ||
, defaultCliEnvSettings | ||
) where | ||
|
||
import Data.Kind (Type) | ||
import qualified Options.Applicative as Opt | ||
import Iris.Cli.Version (VersionSettings) | ||
import Iris.Tool (Tool) | ||
|
||
{- | | ||
@since 0.0.0.0 | ||
-} | ||
data CliEnvSettings (cmd :: Type) (appEnv :: Type) = CliEnvSettings | ||
{ -- | @since 0.0.0.0 | ||
cliEnvSettingsCmdParser :: Opt.Parser cmd | ||
|
||
-- | @since 0.0.0.0 | ||
, cliEnvSettingsAppEnv :: appEnv | ||
|
||
-- | @since 0.0.0.0 | ||
, cliEnvSettingsHeaderDesc :: String | ||
|
||
-- | @since 0.0.0.0 | ||
, cliEnvSettingsProgDesc :: String | ||
|
||
-- | @since 0.0.0.0 | ||
, cliEnvSettingsVersionSettings :: Maybe VersionSettings | ||
|
||
-- | @since 0.0.0.0 | ||
, cliEnvSettingsRequiredTools :: [Tool cmd] | ||
} | ||
|
||
|
||
{- | | ||
@since 0.0.0.0 | ||
-} | ||
defaultCliEnvSettings :: CliEnvSettings () () | ||
defaultCliEnvSettings = CliEnvSettings | ||
{ cliEnvSettingsCmdParser = pure () | ||
, cliEnvSettingsAppEnv = () | ||
, cliEnvSettingsHeaderDesc = "Simple CLI program" | ||
, cliEnvSettingsProgDesc = "CLI tool build with iris - a Haskell CLI framework" | ||
, cliEnvSettingsVersionSettings = Nothing | ||
, cliEnvSettingsRequiredTools = [] | ||
} |
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.