module App.ParseArgs (parse_args) where
import qualified Control.Monad.Trans as Trans
import qualified Data.Text as Text
import qualified Cmd.Cmd as Cmd
import qualified Cmd.Create as Create
import qualified Cmd.Load.Midi as Load.Midi
import qualified Cmd.Save as Save
import qualified Cmd.SaveGit as SaveGit
import Global
parse_args :: [String] -> Either Text (Cmd.CmdT IO Cmd.Status)
parse_args :: [String] -> Either Text (CmdT IO Status)
parse_args = \case
[] -> forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ String -> CmdT IO ()
Save.load_template String
"save/default" forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return Status
Cmd.Done
[String
"-t", String
fn] -> forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ String -> CmdT IO ()
Save.load_template String
fn forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return Status
Cmd.Done
[String
"midi", String
fn] -> forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ String -> CmdT IO Status
load_midi String
fn
[String
fn] -> forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ String -> CmdT IO ()
Save.load String
fn forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return Status
Cmd.Done
[String
fn, String
ref_or_commit] -> forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ do
Commit
commit <- forall (m :: * -> *) a. (Stack, M m) => Text -> Maybe a -> m a
Cmd.require (Text
"not a ref or commit: " forall a. Semigroup a => a -> a -> a
<> String -> Text
txt String
ref_or_commit)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *) a. MonadIO m => IO a -> m a
Trans.liftIO (String -> String -> IO (Maybe Commit)
SaveGit.infer_commit String
fn String
ref_or_commit)
String -> Maybe Commit -> CmdT IO ()
Save.load_git String
fn (forall a. a -> Maybe a
Just Commit
commit)
forall (m :: * -> *) a. Monad m => a -> m a
return Status
Cmd.Done
[String]
args -> forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ [Text] -> Text
Text.unlines
[ Text
"Expected:"
, Text
"<filename> - load score"
, Text
"<repo.git> - load git repo"
, Text
"<repo.git> <hash> - load git repo at a particular commit\
\\n (GIT_DIR=score.git git log to see them)"
, Text
"-t <template> - load score but don't set default save path"
, Text
"midi <score.mid> - load MIDI file"
, Text
""
, Text
"But got: " forall a. Semigroup a => a -> a -> a
<> forall a. Pretty a => a -> Text
pretty [String]
args
]
load_midi :: FilePath -> Cmd.CmdT IO Cmd.Status
load_midi :: String -> CmdT IO Status
load_midi String
fn = do
BlockId
block_id <- String -> CmdT IO BlockId
Load.Midi.load String
fn
forall (m :: * -> *). M m => BlockId -> m ViewId
Create.unfitted_view BlockId
block_id
forall (m :: * -> *) a. Monad m => a -> m a
return Status
Cmd.Done