Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve API for detecting required tools on start #32

Open
2 tasks
chshersh opened this issue Jun 25, 2022 · 2 comments
Open
2 tasks

Improve API for detecting required tools on start #32

chshersh opened this issue Jun 25, 2022 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@chshersh
Copy link
Owner

chshersh commented Jun 25, 2022

Iris.need is the main function for checking whether a specified tool executable in PATH:

need :: MonadIO m => [Tool] -> m ()

It supposed to be used like this in the main application code:

app :: App ()
app = Iris.asksCliEnv Iris.cliEnvCmd >>= \case
    Download url -> do
        need ["curl"]
        runDownload url
    Evaluate hs -> do
        need ["ghc", "cabal"]
        runEvaluate hs

Where the Tool type is the following:

iris/src/Iris/Tool.hs

Lines 43 to 71 in c1597ee

data Tool = Tool
{ toolName :: Text
-- ^ @since 0.0.0.0
, toolSelector :: Maybe ToolSelector
-- ^ @since 0.0.0.0
}
{- |
@since 0.0.0.0
-}
instance IsString Tool where
fromString :: String -> Tool
fromString s =
Tool
{ toolName = fromString s
, toolSelector = Nothing
}
{- |
@since 0.0.0.0
-}
data ToolSelector = ToolSelector
{ toolSelectorFunction :: Text -> Bool
-- ^ @since 0.0.0.0
, toolSelectorVersionArg :: Maybe Text
-- ^ @since 0.0.0.0
}

It does the job but it's a bit suboptimal and maybe inconvenient at times.

I'd love to improve this API in the following way:

  • Provide eDSL for specifying the minimum required version
  • Provide eDSL for specifying the flag for checking the version

With such an eDSL, it should be possible to write the following code:

ghc :: Iris.Tool
ghc = "ghc" `Iris.versionAtLeast` [8, 10, 7] `Iris.usingVersionFlag` "--numeric-version"

cabal :: Iris.Tool
cabal = "cabal" `Iris.versionAtLeast` [3, 6, 2, 0] `Iris.usingVersionFlag` "--numeric-version"

app :: App ()
app = Iris.asksCliEnv Iris.cliEnvCmd >>= \case
    Download url -> do
        need ["curl"]
        runDownload url
    Evaluate hs -> do
        need [ghc, cabal]
        runEvaluate hs

The checkToolFunction should patched accordingly.

@chshersh chshersh added the enhancement New feature or request label Jun 25, 2022
@chshersh chshersh moved this to Todo in Iris Project Jun 25, 2022
@chshersh chshersh added good first issue Good for newcomers help wanted Extra attention is needed and removed good first issue Good for newcomers labels Aug 8, 2022
@chshersh
Copy link
Owner Author

chshersh commented Oct 1, 2022

Part of the API improvements are described in:

@german1608
Copy link
Contributor

I'd like to work on this after #97 is merged, but I don't understand what you're suggesting on the second task. Could you help clarifying it please?

@chshersh chshersh added good first issue Good for newcomers and removed help wanted Extra attention is needed labels Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
No open projects
Status: Todo
Development

No branches or pull requests

2 participants