diff --git a/app/Commands/Dev/Anoma.hs b/app/Commands/Dev/Anoma.hs
index cffaf44f38..944f297b43 100644
--- a/app/Commands/Dev/Anoma.hs
+++ b/app/Commands/Dev/Anoma.hs
@@ -13,36 +13,33 @@ import Commands.Dev.Anoma.Base
import Commands.Dev.Anoma.Client
import Commands.Dev.Anoma.Options
import Commands.Dev.Anoma.Prove qualified as Prove
-import Commands.Dev.Anoma.Prove.Options
import Commands.Dev.Anoma.Start qualified as Start
import Juvix.Data.CodeAnn
import Juvix.Data.Yaml qualified as Y
-runCommand :: forall r. (Members AppEffects r) => AnomaCommand -> Sem r ()
-runCommand =
- runAppError @SimpleError . \case
+runCommand :: forall r. (Members AppEffects r) => AnomaCommandGlobal -> Sem r ()
+runCommand g =
+ runAppError @SimpleError $ case (g ^. anomaCommandGlobalCommand) of
AnomaCommandStart opts -> Start.runCommand opts
AnomaCommandStatus -> checkRunning >>= renderStdOutLn . ppCodeAnn
AnomaCommandStop -> checkRunning >>= stopClient >> removeConfig
AnomaCommandProve opts ->
runAnomaWithHostConfig
- (opts ^. proveClientInfo)
(Prove.runCommand opts)
AnomaCommandAddTransaction opts ->
runAnomaWithHostConfig
- (opts ^. addTransactionClientInfo)
(addTransaction (opts ^. addTransactionFile))
where
- runAnomaWithHostConfig :: (Members (Error SimpleError ': AppEffects) x) => Maybe (AppPath File) -> Sem (Anoma ': x) () -> Sem x ()
- runAnomaWithHostConfig mconfigFile eff = do
- host <- getHostConfig mconfigFile
+ runAnomaWithHostConfig :: (Members (Error SimpleError ': AppEffects) x) => Sem (Anoma ': x) () -> Sem x ()
+ runAnomaWithHostConfig eff = do
+ host <- getHostConfig
runAnomaWithClient host eff
checkRunning :: (Members (Error SimpleError ': AppEffects) x) => Sem x ClientConfig
checkRunning = fromMaybeM (logInfo "The Anoma client is not running" >> exitFailure) checkClientRunning
- getHostConfig :: (Members (Error SimpleError ': AppEffects) x) => Maybe (AppPath File) -> Sem x AnomaClientInfo
- getHostConfig = \case
+ getHostConfig :: (Members (Error SimpleError ': AppEffects) x) => Sem x AnomaClientInfo
+ getHostConfig = case g ^. anomaCommandGlobalClientConfig of
Just p -> fromAppFile p >>= readClientInfo
Nothing -> (^. clientConfigHost) <$> checkRunning
diff --git a/app/Commands/Dev/Anoma/AddTransaction/Options.hs b/app/Commands/Dev/Anoma/AddTransaction/Options.hs
index adb52031f8..a772627ff9 100644
--- a/app/Commands/Dev/Anoma/AddTransaction/Options.hs
+++ b/app/Commands/Dev/Anoma/AddTransaction/Options.hs
@@ -2,9 +2,8 @@ module Commands.Dev.Anoma.AddTransaction.Options where
import CommonOptions
-data AddTransactionOptions = AddTransactionOptions
- { _addTransactionFile :: AppPath File,
- _addTransactionClientInfo :: Maybe (AppPath File)
+newtype AddTransactionOptions = AddTransactionOptions
+ { _addTransactionFile :: AppPath File
}
deriving stock (Data)
@@ -13,5 +12,4 @@ makeLenses ''AddTransactionOptions
parseAddTransactionOptions :: Parser AddTransactionOptions
parseAddTransactionOptions = do
_addTransactionFile <- parseInputFile FileExtNockma
- _addTransactionClientInfo <- optional anomaClientConfigOpt
pure AddTransactionOptions {..}
diff --git a/app/Commands/Dev/Anoma/Options.hs b/app/Commands/Dev/Anoma/Options.hs
index 8a8685425d..197e2100f2 100644
--- a/app/Commands/Dev/Anoma/Options.hs
+++ b/app/Commands/Dev/Anoma/Options.hs
@@ -13,17 +13,27 @@ data AnomaCommand
| AnomaCommandAddTransaction AddTransactionOptions
deriving stock (Data)
-parseAnomaCommand :: Parser AnomaCommand
+data AnomaCommandGlobal = AnomaCommandGlobal
+ { _anomaCommandGlobalClientConfig :: Maybe (AppPath File),
+ _anomaCommandGlobalCommand :: AnomaCommand
+ }
+ deriving stock (Data)
+
+makeLenses ''AnomaCommandGlobal
+
+parseAnomaCommand :: Parser AnomaCommandGlobal
parseAnomaCommand =
- hsubparser
- ( mconcat
- [ commandStart,
- commandStatus,
- commandStop,
- commandProve,
- commandAddTransaction
- ]
- )
+ AnomaCommandGlobal
+ <$> optional anomaClientConfigOpt
+ <*> hsubparser
+ ( mconcat
+ [ commandStart,
+ commandStatus,
+ commandStop,
+ commandProve,
+ commandAddTransaction
+ ]
+ )
where
commandStart :: Mod CommandFields AnomaCommand
commandStart = command "start" runInfo
@@ -63,15 +73,12 @@ parseAnomaCommand =
( Just
( vsep
( [ "The prove command submits a Nockma program to the Anoma.Protobuf.NockService.Prove gRPC endpoint.",
- ""
+ "",
+ "The gRPC response (a Nockma program) is saved to a file named .proved.nockma, where is the base name of the input file.",
+ "Use the -o/--output option to specify a custom output filename.",
+ "",
+ "If the program generates traces, they will be written to standard output."
]
- <> configHelp
- <> [ "",
- "The gRPC response (a Nockma program) is saved to a file named .proved.nockma, where is the base name of the input file.",
- "Use the -o/--output option to specify a custom output filename.",
- "",
- "If the program generates traces, they will be written to standard output."
- ]
)
)
)
@@ -85,26 +92,4 @@ parseAnomaCommand =
runInfo =
info
(AnomaCommandAddTransaction <$> parseAddTransactionOptions)
- ( headerDoc
- ( Just
- ( vsep
- ( [ "The add-transaction command submits a Nockma transaction candidate to the Anoma.Protobuf.Mempool.AddTransaction gRPC endpoint.",
- ""
- ]
- <> configHelp
- )
- )
- )
- <> progDesc "Submit a Nockma transaction candidate to Anoma.Protobuf.Mempool.AddTransaction"
- )
-
-configHelp :: [Doc AnsiStyle]
-configHelp =
- [ "By default, the gRPC request is made to the client that is started by juvix dev anoma start.",
- "Use the -c/--config option to use a different Anoma client.",
- "The config file format is:",
- "",
- "url: ",
- "port: ",
- "nodeid: "
- ]
+ (progDesc "Submit a Nockma transaction candidate to Anoma.Protobuf.Mempool.AddTransaction")
diff --git a/app/Commands/Dev/Anoma/Prove/Options.hs b/app/Commands/Dev/Anoma/Prove/Options.hs
index 35be6cfe0f..3faf72d333 100644
--- a/app/Commands/Dev/Anoma/Prove/Options.hs
+++ b/app/Commands/Dev/Anoma/Prove/Options.hs
@@ -5,7 +5,6 @@ import CommonOptions
data ProveOptions = ProveOptions
{ _proveFile :: AppPath File,
_proveArgs :: Maybe (AppPath File),
- _proveClientInfo :: Maybe (AppPath File),
_proveOutputFile :: Maybe (AppPath File)
}
deriving stock (Data)
@@ -16,6 +15,5 @@ parseProveOptions :: Parser ProveOptions
parseProveOptions = do
_proveFile <- parseInputFile FileExtNockma
_proveArgs <- optional anomaArgsOpt
- _proveClientInfo <- optional anomaClientConfigOpt
_proveOutputFile <- optional parseGenericOutputFile
pure ProveOptions {..}
diff --git a/app/Commands/Dev/Options.hs b/app/Commands/Dev/Options.hs
index fb5b426d0d..1744ad8c4e 100644
--- a/app/Commands/Dev/Options.hs
+++ b/app/Commands/Dev/Options.hs
@@ -53,7 +53,7 @@ data DevCommand
| JuvixDevRepl ReplOptions
| MigrateJuvixYaml MigrateJuvixYamlOptions
| Nockma NockmaCommand
- | Anoma AnomaCommand
+ | Anoma AnomaCommandGlobal
deriving stock (Data)
parseDevCommand :: Parser DevCommand
@@ -212,7 +212,25 @@ commandNockma =
commandAnoma :: Mod CommandFields DevCommand
commandAnoma =
- command "anoma" $
- info
- (Anoma <$> parseAnomaCommand)
- (progDesc "Subcommands related to the Anoma client")
+ let descr :: (IsString a) => a
+ descr = "Subcommands related to the Anoma client"
+ in command "anoma" $
+ info
+ (Anoma <$> parseAnomaCommand)
+ ( headerDoc
+ ( Just
+ ( vsep
+ [ descr,
+ "",
+ "By default, the gRPC request is made to the client that is started by juvix dev anoma start.",
+ "Use the -c/--config option to use a different Anoma client.",
+ "The config file format is:",
+ "",
+ "url: ",
+ "port: ",
+ "nodeid: "
+ ]
+ )
+ )
+ <> progDesc descr
+ )