chshersh / iris

🌈 Haskell CLI Framework supporting Command Line Interface Guidelines
https://hackage.haskell.org/package/iris
Mozilla Public License 2.0
176 stars 21 forks source link

Running shell commands #28

Open chshersh opened 2 years ago

chshersh commented 2 years ago

Implement functions to run Shell commands easier in the Iris applications. A simple implementation would be something like this (inspired by shellmet):

-- | Run the command but don't print it
shellSilent
    :: FilePath  -- ^ Executable name
    -> [Text]    -- ^ Arguments
    -> IO ()

-- | Run the command and print the command itself to stderr
shell
    :: Text      -- ^ Prompt
    -> FilePath  -- ^ Executable name
    -> [Text]    -- ^ Arguments
    -> IO ()

-- | Run the command, don't print it and return its stdout
shellRetSilent
    :: FilePath  -- ^ Executable name
    -> [Text]    -- ^ Arguments
    -> IO Text

-- | Run the command, print it with prompt to stderr and return its stdout
shellRet
    :: Text      -- ^ Prompt
    -> FilePath  -- ^ Executable name
    -> [Text]    -- ^ Arguments
    -> IO Text

Alternatively, we can integrate with one of the existing and battle-tested libraries:

Possible usage inside Iris itself — Iris.Browse module:

https://github.com/chshersh/iris/blob/7e694331069c7732fa70235767c472e23dbf402b/src/Iris/Browse.hs#L69-L74

Open questions: