8000 Running shell commands · Issue #28 · chshersh/iris · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Running shell commands #28
Open
Open
@chshersh

Description

@chshersh

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:

iris/src/Iris/Browse.hs

Lines 69 to 74 in 7e69433

-- | Execute a command with arguments.
runCommand :: FilePath -> [String] -> IO ()
runCommand cmd args = do
let cmdStr = showCommandForUser cmd args
putStrLn $ "" ++ cmdStr
callCommand cmdStr

Open questions:

  • Would it make sense to run those commands in MonadReader CliEnv to use something specific for running shell commands?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0