Skip to content

Commit

Permalink
Merge pull request #277 from Concordium/show-all-options
Browse files Browse the repository at this point in the history
Show the format flag when importing an account
  • Loading branch information
MilkywayPirate authored Sep 19, 2023
2 parents fd3b287 + b053bcd commit 650e6c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
4 changes: 3 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
- `GetBakerEarliestWinTime`
- `GetWinningBakersEpoch`
- `GetFirstBlockEpoch`
- Add support for `CommissionRates` in `CurrentPaydayBakerPoolStatus` (Only available for node versions > 6.0).
- Add support for `CommissionRates` in `CurrentPaydayBakerPoolStatus` (Only available for node versions > 6.0).
- Show all options for importing an account.


## 6.0.1

Expand Down
5 changes: 1 addition & 4 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ module Main where

import Concordium.Client.Commands
import Concordium.Client.Runner
import Data.Maybe
import Options.Applicative
import System.Environment
import System.IO

ccPrefs :: ParserPrefs
Expand All @@ -29,5 +27,4 @@ setReplacement h = do
main :: IO ()
main = do
mapM_ setReplacement [stdout, stderr]
showAllOpts <- lookupEnv "SHOW_ALL_OPTS"
process =<< customExecParser ccPrefs (optsParser $ isJust showAllOpts)
process =<< customExecParser ccPrefs optsParser
40 changes: 16 additions & 24 deletions src/Concordium/Client/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,6 @@ data IdentityShowCmd
{isarsBlockHash :: !(Maybe Text)}
deriving (Show)

type ShowAllOpts = Bool

internalUnless :: ShowAllOpts -> Mod f a
internalUnless showAllOpts = if showAllOpts then idm else internal

visibleHelper :: Parser (a -> a)
visibleHelper =
abortOption (ShowHelpText Nothing) $
Expand All @@ -560,10 +555,10 @@ visibleHelper =
help "Show detailed help text."
]

optsParser :: ShowAllOpts -> ParserInfo Options
optsParser showAllOpts =
optsParser :: ParserInfo Options
optsParser =
info
(programOptions showAllOpts <**> versionOption <**> visibleHelper)
(programOptions <**> versionOption <**> visibleHelper)
( fullDesc
<> progDesc "Concordium Client CLI."
<> header "concordium-client - a client to interact with the concordium network."
Expand Down Expand Up @@ -660,16 +655,16 @@ interactionOptsParser =
<$> (not <$> switch (long "no-confirm" <> help "Do not ask for confirmation before proceeding to send the transaction."))
<*> (not <$> switch (long "no-wait" <> help "Exit right after sending the transaction without waiting for it to be committed and finalized."))

programOptions :: ShowAllOpts -> Parser Options
programOptions showAllOpts =
programOptions :: Parser Options
programOptions =
Options
<$> hsubparser
( metavar "command"
<> transactionCmds
<> accountCmds
<> moduleCmds
<> contractCmds
<> configCmds showAllOpts
<> configCmds
<> consensusCmds
<> blockCmds
<> bakerCmds
Expand Down Expand Up @@ -1297,8 +1292,8 @@ contractRemoveNameCmd =
)
)

configCmds :: ShowAllOpts -> Mod CommandFields Cmd
configCmds showAllOpts =
configCmds :: Mod CommandFields Cmd
configCmds =
command
"config"
( info
Expand All @@ -1308,7 +1303,7 @@ configCmds showAllOpts =
<> configShowCmd
<> configBackupExportCmd
<> configBackupImportCmd
<> configAccountCmds showAllOpts
<> configAccountCmds
)
)
(progDesc "Commands for inspecting and changing local configuration.")
Expand Down Expand Up @@ -1355,16 +1350,16 @@ configBackupImportCmd =
(progDesc "Import config backup file, requires password if encrypted")
)

configAccountCmds :: ShowAllOpts -> Mod CommandFields ConfigCmd
configAccountCmds showAllOpts =
configAccountCmds :: Mod CommandFields ConfigCmd
configAccountCmds =
command
"account"
( info
( ConfigAccountCmd
<$> hsubparser
( configAccountNameCmd
<> configAccountRemove
<> configAccountImportCmd showAllOpts
<> configAccountImportCmd
<> configAccountAddKeysCmd
<> configAccountUpdateKeysCmd
<> configAccountChangeKeyPasswordCmd
Expand Down Expand Up @@ -1398,24 +1393,21 @@ configAccountRemove =
(progDesc "Remove the account from the persistent config.")
)

configAccountImportCmd :: ShowAllOpts -> Mod CommandFields ConfigAccountCmd
configAccountImportCmd showAllOpts =
configAccountImportCmd :: Mod CommandFields ConfigAccountCmd
configAccountImportCmd =
command
"import"
( info
( ConfigAccountImport
<$> strArgument (metavar "FILE" <> help "File with one or more accounts exported from the wallet.")
<*> optional (strOption (long "name" <> metavar "NAME" <> help nameOptionHelp))
<*> option readAccountExportFormat (internalUnless showAllOpts <> long "format" <> metavar "FORMAT" <> value FormatMobile <> help "Export format. Supported values are 'mobile' and 'genesis' (default: 'mobile').")
<*> option readAccountExportFormat (long "format" <> metavar "FORMAT" <> value FormatMobile <> help "Export format. Supported values are 'mobile' and 'genesis' (default: 'mobile').")
<*> switch (long "skip-existing" <> short 's' <> help "Automatically skip importing accounts when the keydirectory already exists")
)
(progDesc "Import an account to persistent config.")
)
where
nameOptionHelp =
if showAllOpts
then "Name of the account. For the 'genesis' format, this sets the name to assign to the account. For the 'mobile' format (which contains multiple already named accounts), it selects which account to import."
else "Name of a single account in the wallet. This will cause the client to only import that account."
nameOptionHelp = "Name of the account. For the 'genesis' format, this sets the name to assign to the account. For the 'mobile' format (which contains multiple already named accounts), it selects which account to import."

configAccountAddKeysCmd :: Mod CommandFields ConfigAccountCmd
configAccountAddKeysCmd =
Expand Down

0 comments on commit 650e6c3

Please sign in to comment.