Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit 0a6feda

Browse files
committed
Simplify code and add check for version 1
1 parent 3c59895 commit 0a6feda

3 files changed

Lines changed: 9 additions & 19 deletions

File tree

internals/onepassword/cli_v1.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ import (
66
"fmt"
77
)
88

9-
type OPV1CLI struct {
10-
version string
11-
isV2 bool
12-
}
9+
type OPV1CLI struct{}
1310

1411
func (op *OPV1CLI) IsV2() bool {
15-
return op.isV2
12+
return false
1613
}
1714

1815
func (op *OPV1CLI) CreateVault(name string) error {

internals/onepassword/cli_v2.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ import (
77
"os"
88
)
99

10-
type OPV2CLI struct {
11-
version string
12-
isV2 bool
13-
}
10+
type OPV2CLI struct{}
1411

1512
func (op *OPV2CLI) IsV2() bool {
16-
return op.isV2
13+
return true
1714
}
1815

1916
func (op *OPV2CLI) CreateVault(name string) error {

internals/onepassword/onepassword.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,11 @@ func GetOPClient() (OPCLI, error) {
3232
version := strings.TrimSpace(string(out))
3333

3434
if strings.HasPrefix(version, "2.") {
35-
return &OPV2CLI{
36-
version: version,
37-
isV2: true,
38-
}, nil
39-
}
40-
return &OPV1CLI{
41-
version: version,
42-
isV2: false,
43-
}, nil
35+
return &OPV2CLI{}, nil
36+
} else if strings.HasPrefix(version, "1.") {
37+
return &OPV1CLI{}, nil
38+
}
39+
return nil, fmt.Errorf("1password: op version not recognized")
4440
}
4541

4642
func NewItemTemplate() *ItemTemplate {

0 commit comments

Comments
 (0)