Skip to content

Commit b1fce04

Browse files
committed
chore: mark all root command flags as Local
With this change, we don't need the Go template hack anymore. The help text for subcommands displays correctly without showing global options. Signed-off-by: Hoang Nguyen <[email protected]>
1 parent eea878e commit b1fce04

File tree

1 file changed

+62
-20
lines changed

1 file changed

+62
-20
lines changed

cmd/sops/main.go

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,6 @@ func warnMoreThanOnePositionalArgument(c *cli.Command) {
7777
func main() {
7878
cli.VersionPrinter = version.PrintVersion
7979

80-
// Remove GLOBAL OPTIONS from the help text of subcommands
81-
cli.CommandHelpTemplate = `NAME:
82-
{{template "helpNameTemplate" .}}
83-
84-
USAGE:
85-
{{template "usageTemplate" .}}{{if .Category}}
86-
87-
CATEGORY:
88-
{{.Category}}{{end}}{{if .Description}}
89-
90-
DESCRIPTION:
91-
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
92-
93-
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
94-
95-
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
96-
`
97-
9880
keyserviceFlags := []cli.Flag{
9981
&cli.BoolFlag{
10082
Name: "enable-local-keyservice",
@@ -1679,209 +1661,269 @@ For more information, see the README at https://github.com/getsops/sops`,
16791661
},
16801662
},
16811663

1682-
Flags: append([]cli.Flag{
1664+
Flags: []cli.Flag{
16831665
&cli.BoolFlag{
16841666
Name: "decrypt",
16851667
Aliases: []string{"d"},
1668+
Local: true,
16861669
Usage: "decrypt a file and output the result to stdout",
16871670
},
16881671
&cli.BoolFlag{
16891672
Name: "encrypt",
16901673
Aliases: []string{"e"},
1674+
Local: true,
16911675
Usage: "encrypt a file and output the result to stdout",
16921676
},
16931677
&cli.BoolFlag{
16941678
Name: "rotate",
16951679
Aliases: []string{"r"},
1680+
Local: true,
16961681
Usage: "generate a new data encryption key and reencrypt all values with the new key",
16971682
},
16981683
&cli.BoolFlag{
16991684
Name: "disable-version-check",
1685+
Local: true,
17001686
Usage: "do not check whether the current version is latest during --version",
17011687
Sources: cli.EnvVars("SOPS_DISABLE_VERSION_CHECK"),
17021688
},
17031689
&cli.BoolFlag{
17041690
Name: "check-for-updates",
1691+
Local: true,
17051692
Usage: "do check whether the current version is latest during --version",
17061693
},
17071694
&cli.StringFlag{
17081695
Name: "kms",
17091696
Aliases: []string{"k"},
1697+
Local: true,
17101698
Usage: "comma separated list of KMS ARNs",
17111699
Sources: cli.EnvVars("SOPS_KMS_ARN"),
17121700
},
17131701
&cli.StringFlag{
17141702
Name: "aws-profile",
1703+
Local: true,
17151704
Usage: "The AWS profile to use for requests to AWS",
17161705
},
17171706
&cli.StringFlag{
17181707
Name: "gcp-kms",
1708+
Local: true,
17191709
Usage: "comma separated list of GCP KMS resource IDs",
17201710
Sources: cli.EnvVars("SOPS_GCP_KMS_IDS"),
17211711
},
17221712
&cli.StringFlag{
17231713
Name: "azure-kv",
1714+
Local: true,
17241715
Usage: "comma separated list of Azure Key Vault URLs",
17251716
Sources: cli.EnvVars("SOPS_AZURE_KEYVAULT_URLS"),
17261717
},
17271718
&cli.StringFlag{
17281719
Name: "hc-vault-transit",
1720+
Local: true,
17291721
Usage: "comma separated list of vault's key URI (e.g. 'https://vault.example.org:8200/v1/transit/keys/dev')",
17301722
Sources: cli.EnvVars("SOPS_VAULT_URIS"),
17311723
},
17321724
&cli.StringFlag{
17331725
Name: "pgp",
17341726
Aliases: []string{"p"},
1727+
Local: true,
17351728
Usage: "comma separated list of PGP fingerprints",
17361729
Sources: cli.EnvVars("SOPS_PGP_FP"),
17371730
},
17381731
&cli.StringFlag{
17391732
Name: "age",
17401733
Aliases: []string{"a"},
1734+
Local: true,
17411735
Usage: "comma separated list of age recipients",
17421736
Sources: cli.EnvVars("SOPS_AGE_RECIPIENTS"),
17431737
},
17441738
&cli.BoolFlag{
17451739
Name: "in-place",
17461740
Aliases: []string{"i"},
1741+
Local: true,
17471742
Usage: "write output back to the same file instead of stdout",
17481743
},
17491744
&cli.StringFlag{
17501745
Name: "extract",
1746+
Local: true,
17511747
Usage: "extract a specific key or branch from the input document. Decrypt mode only. Example: --extract '[\"somekey\"][0]'",
17521748
},
17531749
&cli.StringFlag{
17541750
Name: "input-type",
1751+
Local: true,
17551752
Usage: "currently json, yaml, dotenv and binary are supported. If not set, sops will use the file's extension to determine the type",
17561753
},
17571754
&cli.StringFlag{
17581755
Name: "output-type",
1756+
Local: true,
17591757
Usage: "currently json, yaml, dotenv and binary are supported. If not set, sops will use the input file's extension to determine the output format",
17601758
},
17611759
&cli.BoolFlag{
17621760
Name: "show-master-keys",
17631761
Aliases: []string{"s"},
1762+
Local: true,
17641763
Usage: "display master encryption keys in the file during editing",
17651764
},
17661765
&cli.StringFlag{
17671766
Name: "add-gcp-kms",
1767+
Local: true,
17681768
Usage: "add the provided comma-separated list of GCP KMS key resource IDs to the list of master keys on the given file",
17691769
},
17701770
&cli.StringFlag{
17711771
Name: "rm-gcp-kms",
1772+
Local: true,
17721773
Usage: "remove the provided comma-separated list of GCP KMS key resource IDs from the list of master keys on the given file",
17731774
},
17741775
&cli.StringFlag{
17751776
Name: "add-azure-kv",
1777+
Local: true,
17761778
Usage: "add the provided comma-separated list of Azure Key Vault key URLs to the list of master keys on the given file",
17771779
},
17781780
&cli.StringFlag{
17791781
Name: "rm-azure-kv",
1782+
Local: true,
17801783
Usage: "remove the provided comma-separated list of Azure Key Vault key URLs from the list of master keys on the given file",
17811784
},
17821785
&cli.StringFlag{
17831786
Name: "add-kms",
1787+
Local: true,
17841788
Usage: "add the provided comma-separated list of KMS ARNs to the list of master keys on the given file",
17851789
},
17861790
&cli.StringFlag{
17871791
Name: "rm-kms",
1792+
Local: true,
17881793
Usage: "remove the provided comma-separated list of KMS ARNs from the list of master keys on the given file",
17891794
},
17901795
&cli.StringFlag{
17911796
Name: "add-hc-vault-transit",
1797+
Local: true,
17921798
Usage: "add the provided comma-separated list of Vault's URI key to the list of master keys on the given file ( eg. https://vault.example.org:8200/v1/transit/keys/dev)",
17931799
},
17941800
&cli.StringFlag{
17951801
Name: "rm-hc-vault-transit",
1802+
Local: true,
17961803
Usage: "remove the provided comma-separated list of Vault's URI key from the list of master keys on the given file ( eg. https://vault.example.org:8200/v1/transit/keys/dev)",
17971804
},
17981805
&cli.StringFlag{
17991806
Name: "add-age",
1807+
Local: true,
18001808
Usage: "add the provided comma-separated list of age recipients fingerprints to the list of master keys on the given file",
18011809
},
18021810
&cli.StringFlag{
18031811
Name: "rm-age",
1812+
Local: true,
18041813
Usage: "remove the provided comma-separated list of age recipients from the list of master keys on the given file",
18051814
},
18061815
&cli.StringFlag{
18071816
Name: "add-pgp",
1817+
Local: true,
18081818
Usage: "add the provided comma-separated list of PGP fingerprints to the list of master keys on the given file",
18091819
},
18101820
&cli.StringFlag{
18111821
Name: "rm-pgp",
1822+
Local: true,
18121823
Usage: "remove the provided comma-separated list of PGP fingerprints from the list of master keys on the given file",
18131824
},
18141825
&cli.BoolFlag{
18151826
Name: "ignore-mac",
1827+
Local: true,
18161828
Usage: "ignore Message Authentication Code during decryption",
18171829
},
18181830
&cli.BoolFlag{
18191831
Name: "mac-only-encrypted",
1832+
Local: true,
18201833
Usage: "compute MAC only over values which end up encrypted",
18211834
},
18221835
&cli.StringFlag{
18231836
Name: "unencrypted-suffix",
1837+
Local: true,
18241838
Usage: "override the unencrypted key suffix.",
18251839
},
18261840
&cli.StringFlag{
18271841
Name: "encrypted-suffix",
1842+
Local: true,
18281843
Usage: "override the encrypted key suffix. When empty, all keys will be encrypted, unless otherwise marked with unencrypted-suffix.",
18291844
},
18301845
&cli.StringFlag{
18311846
Name: "unencrypted-regex",
1847+
Local: true,
18321848
Usage: "set the unencrypted key regex. When specified, only keys matching the regex will be left unencrypted.",
18331849
},
18341850
&cli.StringFlag{
18351851
Name: "encrypted-regex",
1852+
Local: true,
18361853
Usage: "set the encrypted key regex. When specified, only keys matching the regex will be encrypted.",
18371854
},
18381855
&cli.StringFlag{
18391856
Name: "unencrypted-comment-regex",
1857+
Local: true,
18401858
Usage: "set the unencrypted comment suffix. When specified, only keys that have comment matching the regex will be left unencrypted.",
18411859
},
18421860
&cli.StringFlag{
18431861
Name: "encrypted-comment-regex",
1862+
Local: true,
18441863
Usage: "set the encrypted comment suffix. When specified, only keys that have comment matching the regex will be encrypted.",
18451864
},
18461865
&cli.StringFlag{
18471866
Name: "config",
1867+
Local: true,
18481868
Usage: "path to sops' config file. If set, sops will not search for the config file recursively.",
18491869
Sources: cli.EnvVars("SOPS_CONFIG"),
18501870
},
18511871
&cli.StringFlag{
18521872
Name: "encryption-context",
1873+
Local: true,
18531874
Usage: "comma separated list of KMS encryption context key:value pairs",
18541875
},
18551876
&cli.StringFlag{
18561877
Name: "set",
1878+
Local: true,
18571879
Usage: `set a specific key or branch in the input document. value must be a json encoded string. (edit mode only). eg. --set '["somekey"][0] {"somevalue":true}'`,
18581880
},
18591881
&cli.IntFlag{
18601882
Name: "shamir-secret-sharing-threshold",
1883+
Local: true,
18611884
Usage: "the number of master keys required to retrieve the data key with shamir",
18621885
},
18631886
&cli.IntFlag{
18641887
Name: "indent",
1888+
Local: true,
18651889
Usage: "the number of spaces to indent YAML or JSON encoded file",
18661890
},
18671891
&cli.BoolFlag{
18681892
Name: "verbose",
1893+
Local: true,
18691894
Usage: "Enable verbose logging output",
18701895
},
18711896
&cli.StringFlag{
18721897
Name: "output",
1898+
Local: true,
18731899
Usage: "Save the output after encryption or decryption to the file specified",
18741900
},
18751901
&cli.StringFlag{
18761902
Name: "filename-override",
1903+
Local: true,
18771904
Usage: "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type",
18781905
},
18791906
&cli.StringFlag{
18801907
Name: "decryption-order",
1908+
Local: true,
18811909
Usage: "comma separated list of decryption key types",
18821910
Sources: cli.EnvVars("SOPS_DECRYPTION_ORDER"),
18831911
},
1884-
}, keyserviceFlags...),
1912+
// Repeat keyserviceFlags, with Local value set to true
1913+
&cli.BoolFlag{
1914+
Name: "enable-local-keyservice",
1915+
Value: true,
1916+
Local: true,
1917+
Usage: "use local key service",
1918+
Sources: cli.EnvVars("SOPS_ENABLE_LOCAL_KEYSERVICE"),
1919+
},
1920+
&cli.StringSliceFlag{
1921+
Name: "keyservice",
1922+
Local: true,
1923+
Usage: "Specify the key services to use in addition to the local one. Can be specified more than once. Syntax: protocol://address. Example: tcp://myserver.com:5000",
1924+
Sources: cli.EnvVars("SOPS_KEYSERVICE"),
1925+
},
1926+
},
18851927

18861928
Action: func(ctx context.Context, c *cli.Command) error {
18871929
isDecryptMode := c.Bool("decrypt")

0 commit comments

Comments
 (0)