Skip to content

Commit 8f8fcd7

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 dc8ec03 commit 8f8fcd7

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",
@@ -1671,209 +1653,269 @@ For more information, see the README at https://github.com/getsops/sops`,
16711653
},
16721654
},
16731655

1674-
Flags: append([]cli.Flag{
1656+
Flags: []cli.Flag{
16751657
&cli.BoolFlag{
16761658
Name: "decrypt",
16771659
Aliases: []string{"d"},
1660+
Local: true,
16781661
Usage: "decrypt a file and output the result to stdout",
16791662
},
16801663
&cli.BoolFlag{
16811664
Name: "encrypt",
16821665
Aliases: []string{"e"},
1666+
Local: true,
16831667
Usage: "encrypt a file and output the result to stdout",
16841668
},
16851669
&cli.BoolFlag{
16861670
Name: "rotate",
16871671
Aliases: []string{"r"},
1672+
Local: true,
16881673
Usage: "generate a new data encryption key and reencrypt all values with the new key",
16891674
},
16901675
&cli.BoolFlag{
16911676
Name: "disable-version-check",
1677+
Local: true,
16921678
Usage: "do not check whether the current version is latest during --version",
16931679
Sources: cli.EnvVars("SOPS_DISABLE_VERSION_CHECK"),
16941680
},
16951681
&cli.BoolFlag{
16961682
Name: "check-for-updates",
1683+
Local: true,
16971684
Usage: "do check whether the current version is latest during --version",
16981685
},
16991686
&cli.StringFlag{
17001687
Name: "kms",
17011688
Aliases: []string{"k"},
1689+
Local: true,
17021690
Usage: "comma separated list of KMS ARNs",
17031691
Sources: cli.EnvVars("SOPS_KMS_ARN"),
17041692
},
17051693
&cli.StringFlag{
17061694
Name: "aws-profile",
1695+
Local: true,
17071696
Usage: "The AWS profile to use for requests to AWS",
17081697
},
17091698
&cli.StringFlag{
17101699
Name: "gcp-kms",
1700+
Local: true,
17111701
Usage: "comma separated list of GCP KMS resource IDs",
17121702
Sources: cli.EnvVars("SOPS_GCP_KMS_IDS"),
17131703
},
17141704
&cli.StringFlag{
17151705
Name: "azure-kv",
1706+
Local: true,
17161707
Usage: "comma separated list of Azure Key Vault URLs",
17171708
Sources: cli.EnvVars("SOPS_AZURE_KEYVAULT_URLS"),
17181709
},
17191710
&cli.StringFlag{
17201711
Name: "hc-vault-transit",
1712+
Local: true,
17211713
Usage: "comma separated list of vault's key URI (e.g. 'https://vault.example.org:8200/v1/transit/keys/dev')",
17221714
Sources: cli.EnvVars("SOPS_VAULT_URIS"),
17231715
},
17241716
&cli.StringFlag{
17251717
Name: "pgp",
17261718
Aliases: []string{"p"},
1719+
Local: true,
17271720
Usage: "comma separated list of PGP fingerprints",
17281721
Sources: cli.EnvVars("SOPS_PGP_FP"),
17291722
},
17301723
&cli.StringFlag{
17311724
Name: "age",
17321725
Aliases: []string{"a"},
1726+
Local: true,
17331727
Usage: "comma separated list of age recipients",
17341728
Sources: cli.EnvVars("SOPS_AGE_RECIPIENTS"),
17351729
},
17361730
&cli.BoolFlag{
17371731
Name: "in-place",
17381732
Aliases: []string{"i"},
1733+
Local: true,
17391734
Usage: "write output back to the same file instead of stdout",
17401735
},
17411736
&cli.StringFlag{
17421737
Name: "extract",
1738+
Local: true,
17431739
Usage: "extract a specific key or branch from the input document. Decrypt mode only. Example: --extract '[\"somekey\"][0]'",
17441740
},
17451741
&cli.StringFlag{
17461742
Name: "input-type",
1743+
Local: true,
17471744
Usage: "currently json, yaml, dotenv and binary are supported. If not set, sops will use the file's extension to determine the type",
17481745
},
17491746
&cli.StringFlag{
17501747
Name: "output-type",
1748+
Local: true,
17511749
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",
17521750
},
17531751
&cli.BoolFlag{
17541752
Name: "show-master-keys",
17551753
Aliases: []string{"s"},
1754+
Local: true,
17561755
Usage: "display master encryption keys in the file during editing",
17571756
},
17581757
&cli.StringFlag{
17591758
Name: "add-gcp-kms",
1759+
Local: true,
17601760
Usage: "add the provided comma-separated list of GCP KMS key resource IDs to the list of master keys on the given file",
17611761
},
17621762
&cli.StringFlag{
17631763
Name: "rm-gcp-kms",
1764+
Local: true,
17641765
Usage: "remove the provided comma-separated list of GCP KMS key resource IDs from the list of master keys on the given file",
17651766
},
17661767
&cli.StringFlag{
17671768
Name: "add-azure-kv",
1769+
Local: true,
17681770
Usage: "add the provided comma-separated list of Azure Key Vault key URLs to the list of master keys on the given file",
17691771
},
17701772
&cli.StringFlag{
17711773
Name: "rm-azure-kv",
1774+
Local: true,
17721775
Usage: "remove the provided comma-separated list of Azure Key Vault key URLs from the list of master keys on the given file",
17731776
},
17741777
&cli.StringFlag{
17751778
Name: "add-kms",
1779+
Local: true,
17761780
Usage: "add the provided comma-separated list of KMS ARNs to the list of master keys on the given file",
17771781
},
17781782
&cli.StringFlag{
17791783
Name: "rm-kms",
1784+
Local: true,
17801785
Usage: "remove the provided comma-separated list of KMS ARNs from the list of master keys on the given file",
17811786
},
17821787
&cli.StringFlag{
17831788
Name: "add-hc-vault-transit",
1789+
Local: true,
17841790
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)",
17851791
},
17861792
&cli.StringFlag{
17871793
Name: "rm-hc-vault-transit",
1794+
Local: true,
17881795
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)",
17891796
},
17901797
&cli.StringFlag{
17911798
Name: "add-age",
1799+
Local: true,
17921800
Usage: "add the provided comma-separated list of age recipients fingerprints to the list of master keys on the given file",
17931801
},
17941802
&cli.StringFlag{
17951803
Name: "rm-age",
1804+
Local: true,
17961805
Usage: "remove the provided comma-separated list of age recipients from the list of master keys on the given file",
17971806
},
17981807
&cli.StringFlag{
17991808
Name: "add-pgp",
1809+
Local: true,
18001810
Usage: "add the provided comma-separated list of PGP fingerprints to the list of master keys on the given file",
18011811
},
18021812
&cli.StringFlag{
18031813
Name: "rm-pgp",
1814+
Local: true,
18041815
Usage: "remove the provided comma-separated list of PGP fingerprints from the list of master keys on the given file",
18051816
},
18061817
&cli.BoolFlag{
18071818
Name: "ignore-mac",
1819+
Local: true,
18081820
Usage: "ignore Message Authentication Code during decryption",
18091821
},
18101822
&cli.BoolFlag{
18111823
Name: "mac-only-encrypted",
1824+
Local: true,
18121825
Usage: "compute MAC only over values which end up encrypted",
18131826
},
18141827
&cli.StringFlag{
18151828
Name: "unencrypted-suffix",
1829+
Local: true,
18161830
Usage: "override the unencrypted key suffix.",
18171831
},
18181832
&cli.StringFlag{
18191833
Name: "encrypted-suffix",
1834+
Local: true,
18201835
Usage: "override the encrypted key suffix. When empty, all keys will be encrypted, unless otherwise marked with unencrypted-suffix.",
18211836
},
18221837
&cli.StringFlag{
18231838
Name: "unencrypted-regex",
1839+
Local: true,
18241840
Usage: "set the unencrypted key regex. When specified, only keys matching the regex will be left unencrypted.",
18251841
},
18261842
&cli.StringFlag{
18271843
Name: "encrypted-regex",
1844+
Local: true,
18281845
Usage: "set the encrypted key regex. When specified, only keys matching the regex will be encrypted.",
18291846
},
18301847
&cli.StringFlag{
18311848
Name: "unencrypted-comment-regex",
1849+
Local: true,
18321850
Usage: "set the unencrypted comment suffix. When specified, only keys that have comment matching the regex will be left unencrypted.",
18331851
},
18341852
&cli.StringFlag{
18351853
Name: "encrypted-comment-regex",
1854+
Local: true,
18361855
Usage: "set the encrypted comment suffix. When specified, only keys that have comment matching the regex will be encrypted.",
18371856
},
18381857
&cli.StringFlag{
18391858
Name: "config",
1859+
Local: true,
18401860
Usage: "path to sops' config file. If set, sops will not search for the config file recursively.",
18411861
Sources: cli.EnvVars("SOPS_CONFIG"),
18421862
},
18431863
&cli.StringFlag{
18441864
Name: "encryption-context",
1865+
Local: true,
18451866
Usage: "comma separated list of KMS encryption context key:value pairs",
18461867
},
18471868
&cli.StringFlag{
18481869
Name: "set",
1870+
Local: true,
18491871
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}'`,
18501872
},
18511873
&cli.IntFlag{
18521874
Name: "shamir-secret-sharing-threshold",
1875+
Local: true,
18531876
Usage: "the number of master keys required to retrieve the data key with shamir",
18541877
},
18551878
&cli.IntFlag{
18561879
Name: "indent",
1880+
Local: true,
18571881
Usage: "the number of spaces to indent YAML or JSON encoded file",
18581882
},
18591883
&cli.BoolFlag{
18601884
Name: "verbose",
1885+
Local: true,
18611886
Usage: "Enable verbose logging output",
18621887
},
18631888
&cli.StringFlag{
18641889
Name: "output",
1890+
Local: true,
18651891
Usage: "Save the output after encryption or decryption to the file specified",
18661892
},
18671893
&cli.StringFlag{
18681894
Name: "filename-override",
1895+
Local: true,
18691896
Usage: "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type",
18701897
},
18711898
&cli.StringFlag{
18721899
Name: "decryption-order",
1900+
Local: true,
18731901
Usage: "comma separated list of decryption key types",
18741902
Sources: cli.EnvVars("SOPS_DECRYPTION_ORDER"),
18751903
},
1876-
}, keyserviceFlags...),
1904+
// Repeat keyserviceFlags, with Local value set to true
1905+
&cli.BoolFlag{
1906+
Name: "enable-local-keyservice",
1907+
Value: true,
1908+
Local: true,
1909+
Usage: "use local key service",
1910+
Sources: cli.EnvVars("SOPS_ENABLE_LOCAL_KEYSERVICE"),
1911+
},
1912+
&cli.StringSliceFlag{
1913+
Name: "keyservice",
1914+
Local: true,
1915+
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",
1916+
Sources: cli.EnvVars("SOPS_KEYSERVICE"),
1917+
},
1918+
},
18771919

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

0 commit comments

Comments
 (0)