From f09a248fe2e7e66670b9e90d5789802c1f9cb9d9 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 8 May 2023 14:58:08 -0400 Subject: [PATCH] init: Support --json and --json-error-messages Dunno how useful this will be, since about all that's accessible from the json is whether it succeeded or failed, and the error messages which were already on stderr. Note that, when autoenabling a special remote, it would be possible for one to stop and prompt or output not using Messages and so not output as part of the json. I don't think that happens, but I'm not 100% sure something doesn't manage to break it. Of course, the same could be the case for commands that transfer objects. Using Annex.Init.autoEnableSpecialRemotes in --json mode would avoid the problem, but I've chosen to wait until I know it's needed to use it. Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project --- CHANGELOG | 2 +- Command/Init.hs | 2 +- doc/git-annex-init.mdwn | 10 ++++++++++ ...on_for_unannex__and_ideally_any_other_command_.mdwn | 7 +++++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ecd1b86f9d..197cee8499 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -38,7 +38,7 @@ git-annex (10.20230408) UNRELEASED; urgency=medium * initremote: Avoid creating a remote that is not encrypted when gpg is broken. * Support --json and --json-error-messages in more commands - (addunused, dead, describe, dropunused, expire, fix, log, migrate, + (addunused, dead, describe, dropunused, expire, fix, init, log, migrate, rekey, rmurl, semitrust, setpresentkey, trust, unannex, undo, untrust, unused) * log: When --raw-date is used, display only seconds from the epoch, as diff --git a/Command/Init.hs b/Command/Init.hs index fa129b8091..2b7bbeb8a1 100644 --- a/Command/Init.hs +++ b/Command/Init.hs @@ -19,7 +19,7 @@ import Control.Monad.Fail as Fail (MonadFail(..)) import qualified Data.Map as M cmd :: Command -cmd = dontCheck repoExists $ +cmd = dontCheck repoExists $ withAnnexOptions [jsonOptions] $ command "init" SectionSetup "initialize git-annex" paramDesc (seek <$$> optParser) diff --git a/doc/git-annex-init.mdwn b/doc/git-annex-init.mdwn index 09d5e94af1..aa0e418639 100644 --- a/doc/git-annex-init.mdwn +++ b/doc/git-annex-init.mdwn @@ -57,6 +57,16 @@ to the user who tries to run git-annex init. Do not enable special remotes that were configured with autoenable=true. +* `--json` + + Enable JSON output. This is intended to be parsed by programs that use + git-annex. + +* `--json-error-messages` + + Messages that would normally be output to standard error are included in + the JSON instead. + * Also the [[git-annex-common-options]](1) can be used. # SEE ALSO diff --git a/doc/todo/--json_for_unannex__and_ideally_any_other_command_.mdwn b/doc/todo/--json_for_unannex__and_ideally_any_other_command_.mdwn index 1f3230ee76..5e90653e51 100644 --- a/doc/todo/--json_for_unannex__and_ideally_any_other_command_.mdwn +++ b/doc/todo/--json_for_unannex__and_ideally_any_other_command_.mdwn @@ -32,6 +32,7 @@ These commands have been updated to support --json: * git-annex-dead * git-annex-describe * git-annex-unused +* git-annex-init Provisional list of commands that don't support --json and maybe should: @@ -39,8 +40,6 @@ Provisional list of commands that don't support --json and maybe should: * git-annex-configremote * git-annex-enableremote -* git-annex-importfeed -* git-annex-init * git-annex-initremote * git-annex-merge * git-annex-reinit @@ -57,6 +56,10 @@ These commands could support json, but I punted: * git-annex-version (--raw already exists, and the output is fairly machine parseable already. It would be possible to jsonize the output to make it possibly more machine parseable. But I'm doubtful that would be useful. +* git-annex-importfeed (implemented w/o using usual command actions, + which makes warning messages not get put in any particular json record. + Same problem would also need to be fixed for [[doc/todo/importfeed_parallell]] + btw.) These commands have been reviewed and should not support json: