Skip to content

Commit 8d9d1a3

Browse files
otp: hide --snip flag when built with noscreenshot tag (gopasspw#3445)
Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
1 parent 804c5ba commit 8d9d1a3

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

‎internal/action/commands.go‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/gopasspw/gopass/internal/backend"
88
"github.com/gopasspw/gopass/pkg/debug"
9+
"github.com/gopasspw/gopass/pkg/otp"
910
"github.com/gopasspw/gopass/pkg/set"
1011
"github.com/urfave/cli/v3"
1112
)
@@ -890,7 +891,7 @@ func (s *Action) GetCommands() []*cli.Command {
890891
Before: s.IsInitialized,
891892
Action: s.OTP,
892893
ShellComplete: s.Complete,
893-
Flags: []cli.Flag{
894+
Flags: append([]cli.Flag{
894895
&cli.BoolFlag{
895896
Name: "alsoclip",
896897
Aliases: []string{"C"},
@@ -916,12 +917,7 @@ func (s *Action) GetCommands() []*cli.Command {
916917
Aliases: []string{"o"},
917918
Usage: "Only display the token",
918919
},
919-
&cli.BoolFlag{
920-
Name: "snip",
921-
Aliases: []string{"s"},
922-
Usage: "Scan screen content to insert a OTP QR code into provided entry",
923-
},
924-
},
920+
}, otp.SnipFlags()...),
925921
},
926922
{
927923
Name: "process",

‎pkg/otp/screenshot_others.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ package otp
55
import (
66
"context"
77
"fmt"
8+
9+
"github.com/urfave/cli/v3"
810
)
911

1012
// ParseScreen will attempt to parse all available screen and will look for otpauth QR codes. It returns the first one
1113
// it has found.
1214
func ParseScreen(ctx context.Context) (string, error) {
1315
return "", fmt.Errorf("not supported on your platform")
1416
}
17+
18+
// SnipFlags returns an empty slice because the screen-capture feature is not available in this build.
19+
func SnipFlags() []cli.Flag {
20+
return nil
21+
}

‎pkg/otp/screenshot_supported.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ import (
1010
"github.com/kbinani/screenshot"
1111
"github.com/makiuchi-d/gozxing"
1212
"github.com/makiuchi-d/gozxing/qrcode"
13+
"github.com/urfave/cli/v3"
1314
)
1415

16+
// SnipFlags returns the CLI flags for the screen-capture (snip) feature.
17+
func SnipFlags() []cli.Flag {
18+
return []cli.Flag{
19+
&cli.BoolFlag{
20+
Name: "snip",
21+
Aliases: []string{"s"},
22+
Usage: "Scan screen content to insert a OTP QR code into provided entry",
23+
},
24+
}
25+
}
26+
1527
// ParseScreen will attempt to parse all available screen and will look for otpauth QR codes. It returns the first one
1628
// it has found.
1729
func ParseScreen(ctx context.Context) (string, error) {

0 commit comments

Comments
 (0)
⌂ 换网址