anyref commands

This commit is contained in:
Dmitry Zuikov 2023-09-21 11:34:36 +03:00
parent 7856129853
commit 18255c55f5
1 changed files with 19 additions and 2 deletions

View File

@ -364,6 +364,10 @@ runAnyRefGet s ss = do
print $ pretty ref print $ pretty ref
exitSuccess exitSuccess
runAnyRefSet :: forall s t . IsRefPubKey s => AnyRefKey t s -> HashRef -> SimpleStorage HbSync -> IO ()
runAnyRefSet s hr ss = do
updateRef ss s (fromHashRef hr)
withStore :: Data opts => opts -> ( SimpleStorage HbSync -> IO () ) -> IO () withStore :: Data opts => opts -> ( SimpleStorage HbSync -> IO () ) -> IO ()
withStore opts f = do withStore opts f = do
@ -420,6 +424,7 @@ main = join . customExecParser (prefs showHelpOnError) $
<> command "groupkey-new" (info pNewGroupkey (progDesc "generates a new groupkey")) <> command "groupkey-new" (info pNewGroupkey (progDesc "generates a new groupkey"))
<> command "reflog" (info pReflog (progDesc "reflog commands")) <> command "reflog" (info pReflog (progDesc "reflog commands"))
<> command "bundle" (info pBundle (progDesc "bundle commands")) <> command "bundle" (info pBundle (progDesc "bundle commands"))
<> command "anyref" (info pAnyRef (progDesc "anyref commands"))
) )
common = do common = do
@ -482,13 +487,23 @@ main = join . customExecParser (prefs showHelpOnError) $
pure $ withStore o (runRefLogGet @HBS2Basic reflogs) pure $ withStore o (runRefLogGet @HBS2Basic reflogs)
pAnyRef = hsubparser ( command "get" (info pAnyRefGet (progDesc "get anyref value") ) ) pAnyRef = hsubparser ( command "get" (info pAnyRefGet (progDesc "get anyref value") )
<> command "set" (info pAnyRefSet (progDesc "set anyref value") )
)
pAnyRefGet = do pAnyRefGet = do
o <- common o <- common
anyref <- strArgument ( metavar "ANYREF" ) anyref <- strArgument ( metavar "ANYREF" )
pure $ withStore o (runAnyRefGet @HBS2Basic anyref) pure $ withStore o (runAnyRefGet @HBS2Basic anyref)
pAnyRefSet = do
o <- common
anyref <- strArgument ( metavar "ANYREF" )
val <- strArgument ( metavar "HASHREF" )
pure $ do
hr <- pure (fromStringMay val) `orDie` "bad HASHREF"
withStore o (runAnyRefSet @HBS2Basic anyref hr)
pFsck = do pFsck = do
o <- common o <- common
pure $ withStore o $ \sto -> do pure $ withStore o $ \sto -> do
@ -628,3 +643,5 @@ main = join . customExecParser (prefs showHelpOnError) $
printHash = void . print . pretty . fst printHash = void . print . pretty . fst