From 95d084f71ca84400dd24030ec608c84727bc5405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 6 Jul 2025 12:48:04 +0200 Subject: Shell command Changelog: Added `shell` command to open a shell prepared for given job --- minici.cabal | 1 + src/Command/Shell.hs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/Job.hs | 1 + src/Main.hs | 2 ++ 4 files changed, 50 insertions(+) create mode 100644 src/Command/Shell.hs diff --git a/minici.cabal b/minici.cabal index c8d0fe5..d09b495 100644 --- a/minici.cabal +++ b/minici.cabal @@ -53,6 +53,7 @@ executable minici Command.JobId Command.Log Command.Run + Command.Shell Command.Subtree Config Eval diff --git a/src/Command/Shell.hs b/src/Command/Shell.hs new file mode 100644 index 0000000..4cd2b7e --- /dev/null +++ b/src/Command/Shell.hs @@ -0,0 +1,46 @@ +module Command.Shell ( + ShellCommand, +) where + +import Control.Monad +import Control.Monad.IO.Class + +import Data.Maybe +import Data.Text (Text) +import Data.Text qualified as T + +import System.Environment +import System.Process hiding (ShellCommand) + +import Command +import Eval +import Job +import Job.Types + + +data ShellCommand = ShellCommand JobRef + +instance Command ShellCommand where + commandName _ = "shell" + commandDescription _ = "Open a shell prepared for given job" + + type CommandArguments ShellCommand = Text + + commandUsage _ = T.unlines $ + [ "Usage: minici shell " + ] + + commandInit _ _ = ShellCommand . parseJobRef + commandExec = cmdShell + + +cmdShell :: ShellCommand -> CommandExec () +cmdShell (ShellCommand ref) = do + einput <- getEvalInput + job <- either (tfail . textEvalError) (return . fst) =<< + liftIO (runEval (evalJobReference ref) einput) + sh <- fromMaybe "/bin/sh" <$> liftIO (lookupEnv "SHELL") + storageDir <- getStorageDir + prepareJob storageDir job $ \checkoutPath _ -> do + liftIO $ withCreateProcess (proc sh []) { cwd = Just checkoutPath } $ \_ _ _ ph -> do + void $ waitForProcess ph diff --git a/src/Job.hs b/src/Job.hs index 6782f6b..21d878c 100644 --- a/src/Job.hs +++ b/src/Job.hs @@ -8,6 +8,7 @@ module Job ( jobStatusFinished, jobStatusFailed, JobManager(..), newJobManager, cancelAllJobs, runJobs, + prepareJob, jobStorageSubdir, copyRecursive, diff --git a/src/Main.hs b/src/Main.hs index ec03acb..83b0ab3 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -25,6 +25,7 @@ import Command.Extract import Command.JobId import Command.Log import Command.Run +import Command.Shell import Command.Subtree import Config import Output @@ -93,6 +94,7 @@ commands = , SC $ Proxy @ExtractCommand , SC $ Proxy @JobIdCommand , SC $ Proxy @LogCommand + , SC $ Proxy @ShellCommand , SC $ Proxy @SubtreeCommand ] -- cgit v1.2.3