-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Init command * Default to tmux-mate.dhall if nothing else passed * Start command * Update readme
- Loading branch information
1 parent
fa1d863
commit 126ce03
Showing
7 changed files
with
117 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module CLICommands where | ||
|
||
import TmuxMate (CLIOptions (..)) | ||
|
||
data CLICommand | ||
= CLIRun CLIOptions | ||
| CLIInit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
module Main where | ||
|
||
import Options.Applicative | ||
import CLICommands | ||
import Options (command) | ||
import qualified Options.Applicative as Opt | ||
import System.Exit | ||
import TmuxMate | ||
|
||
main :: IO () | ||
main = do | ||
options' <- execParser (info options fullDesc) | ||
didItWork <- loadTestSession options' | ||
case didItWork of | ||
Yeah -> exitWith ExitSuccess | ||
Nah i -> exitWith (ExitFailure i) | ||
|
||
configFilePathParser :: Parser ConfigFilePath | ||
configFilePathParser = | ||
ConfigFilePath | ||
<$> argument str (metavar "<path-to-config-file>") | ||
|
||
verbosityParser :: Parser Verbosity | ||
verbosityParser = | ||
flag' Chatty (short 'v' <> long "verbose") | ||
<|> flag' DryRun (short 'd' <> long "dry-run") | ||
<|> pure Silent | ||
|
||
options :: Parser CLIOptions | ||
options = | ||
CLIOptions | ||
<$> configFilePathParser <*> verbosityParser | ||
command' <- Opt.execParser (Opt.info command Opt.fullDesc) | ||
case command' of | ||
CLIInit -> do | ||
createTmuxMateDhall | ||
putStrLn "Initial tmux-mate.dhall created!" | ||
CLIRun options' -> do | ||
didItWork <- loadTestSession options' | ||
case didItWork of | ||
Yeah -> exitWith ExitSuccess | ||
Nah i -> exitWith (ExitFailure i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Options (command) where | ||
|
||
import CLICommands | ||
import Options.Applicative ((<|>)) | ||
import qualified Options.Applicative as Opt | ||
import TmuxMate | ||
|
||
command :: Opt.Parser CLICommand | ||
command = | ||
otherCommands | ||
<|> (CLIRun <$> options) | ||
|
||
configFilePathParser :: Opt.Parser (Maybe ConfigFilePath) | ||
configFilePathParser = | ||
( Just <$> ConfigFilePath | ||
<$> Opt.argument Opt.str (Opt.metavar "<path-to-config-file>") | ||
) | ||
<|> pure Nothing | ||
|
||
verbosityParser :: Opt.Parser Verbosity | ||
verbosityParser = | ||
Opt.flag' Chatty (Opt.short 'v' <> Opt.long "verbose") | ||
<|> Opt.flag' DryRun (Opt.short 'd' <> Opt.long "dry-run") | ||
<|> pure Silent | ||
|
||
options :: Opt.Parser CLIOptions | ||
options = | ||
CLIOptions | ||
<$> configFilePathParser <*> verbosityParser | ||
|
||
otherCommands :: Opt.Parser CLICommand | ||
otherCommands = | ||
Opt.subparser | ||
( Opt.command | ||
"init" | ||
( Opt.info | ||
(pure CLIInit) | ||
(Opt.progDesc "Initialise a new tmux-mate.dhall file") | ||
) | ||
<> Opt.command | ||
"start" | ||
( Opt.info | ||
(CLIRun <$> options) | ||
(Opt.progDesc "Start running everything in the selected config file") | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module TmuxMate.Init (createTmuxMateDhall) where | ||
|
||
-- where we make a new empty session file | ||
|
||
import Data.Text.IO | ||
import Dhall | ||
import Dhall.Core (pretty) | ||
import TmuxMate.Types | ||
( Pane (..), | ||
PaneArrangement (..), | ||
PaneCommand (..), | ||
Session (..), | ||
SessionName (..), | ||
Window (..), | ||
WindowName (..), | ||
) | ||
|
||
createTmuxMateDhall :: IO () | ||
createTmuxMateDhall = do | ||
let dhallVal = pretty (embed inject defaultSession) | ||
Data.Text.IO.writeFile "./tmux-mate.dhall" dhallVal | ||
|
||
defaultSession :: Session | ||
defaultSession = | ||
Session | ||
(SessionName "tmux-mate") | ||
[ Window | ||
(WindowName "first") | ||
[ Pane | ||
( PaneCommand "watch echo \"hello from tmux-mate\"" | ||
), | ||
Pane | ||
( PaneCommand "watch echo \"hello again from tmux-mate\"" | ||
) | ||
] | ||
(PaneArrangement "tiled") | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters