Skip to content

Commit 96d39a9

Browse files
authored
Move sget -key to --key, support but warn on -key. (#724)
* Move sget -key to --key * Migrate ffcli flags to POSIX with a warning message. Signed-off-by: Scott Nichols <[email protected]>
1 parent acba596 commit 96d39a9

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Fetching contents without verifying them is dangerous, so we require the artifac
234234
$ sget gcr.io/dlorenc-vmtest2/artifact
235235
error: public key must be specified when fetching by tag, you must fetch by digest or supply a public key
236236
237-
$ sget -key cosign.pub us.gcr.io/dlorenc-vmtest2/readme > foo
237+
$ sget --key cosign.pub us.gcr.io/dlorenc-vmtest2/readme > foo
238238
239239
Verification for us.gcr.io/dlorenc-vmtest2/readme --
240240
The following checks were performed on each of these signatures:

cmd/sget/main.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,33 @@
1616
package main
1717

1818
import (
19+
"fmt"
1920
"log"
21+
"os"
22+
"strings"
2023

2124
"github.com/sigstore/cosign/cmd/sget/cli"
2225
)
2326

2427
func main() {
28+
// Fix up flags to POSIX standard flags.
29+
for i, arg := range os.Args {
30+
if (strings.HasPrefix(arg, "-") && len(arg) == 2) || (strings.HasPrefix(arg, "--") && len(arg) >= 4) {
31+
continue
32+
}
33+
if strings.HasPrefix(arg, "--") && len(arg) == 3 {
34+
// Handle --o, convert to -o
35+
newArg := fmt.Sprintf("-%c", arg[2])
36+
fmt.Fprintf(os.Stderr, "WARNING: the flag %s is deprecated and will be removed in a future release. Please use the flag %s.\n", arg, newArg)
37+
os.Args[i] = newArg
38+
} else if strings.HasPrefix(arg, "-") {
39+
// Handle -output, convert to --output
40+
newArg := fmt.Sprintf("-%s", arg)
41+
fmt.Fprintf(os.Stderr, "WARNING: the flag %s is deprecated and will be removed in a future release. Please use the flag %s.\n", arg, newArg)
42+
os.Args[i] = newArg
43+
}
44+
}
45+
2546
if err := cli.New().Execute(); err != nil {
2647
log.Fatalf("error during command execution: %v", err)
2748
}

test/e2e_test_secrets.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ dgst=$(./cosign upload blob -f randomblob ${blobimg})
124124
./cosign verify -key ${verification_key} ${dgst} # For sanity
125125

126126
# sget w/ signature verification should work via tag or digest
127-
./sget -key ${verification_key} -o verified_randomblob_from_digest $dgst
128-
./sget -key ${verification_key} -o verified_randomblob_from_tag $blobimg
127+
./sget --key ${verification_key} -o verified_randomblob_from_digest $dgst
128+
./sget --key ${verification_key} -o verified_randomblob_from_tag $blobimg
129129

130130
# sget w/o signature verification should only work for ref by digest
131-
./sget -key ${verification_key} -o randomblob_from_digest $dgst
131+
./sget --key ${verification_key} -o randomblob_from_digest $dgst
132132
if (./sget -o randomblob_from_tag $blobimg); then false; fi
133133

134134
# clean up a bit

0 commit comments

Comments
 (0)