blob: f125644f33e862ba77042bb62d1c4d73082e3481 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
package git
import (
"context"
"fmt"
)
// noOpMessage is the message printed whenever a git operation is skipped
// because the kdbx file is not inside a git repository.
const noOpMessage = "kdbx file is not in a git repo; skipping"
// NoOp is a no-op git client whose every method prints an informational
// message and returns nil. It is used when the KeePass database file lives
// outside of a git repository so that sync/status/commit/reset commands remain
// functional and transparent rather than crashing or returning errors.
//
// Keeping the no-op behaviour in its own type (rather than nil-checking in the
// CLI dispatch) respects the Open/Closed Principle: the CLI is open for
// extension (new backends, new git behaviours) without modification.
//
// NoOp satisfies the Gitter interface defined in internal/cli (the consumer),
// not here in the producer — per Go best practice #6 from 100 Go Mistakes.
// The compile-time assertion lives in internal/cli/git.go.
type NoOp struct{}
// NewNoOp returns a *NoOp that satisfies Gitter with all operations being
// informational no-ops.
func NewNoOp() *NoOp {
return &NoOp{}
}
// Add prints the no-op message and returns nil.
func (n *NoOp) Add(_ context.Context, _ string) error {
fmt.Printf("> %s\n", noOpMessage)
return nil
}
// Remove prints the no-op message and returns nil.
func (n *NoOp) Remove(_ context.Context, _ string) error {
fmt.Printf("> %s\n", noOpMessage)
return nil
}
// Status prints the no-op message and returns nil.
func (n *NoOp) Status(_ context.Context) error {
fmt.Printf("> %s\n", noOpMessage)
return nil
}
// Commit prints the no-op message and returns nil.
func (n *NoOp) Commit(_ context.Context) error {
fmt.Printf("> %s\n", noOpMessage)
return nil
}
// Reset prints the no-op message and returns nil.
func (n *NoOp) Reset(_ context.Context) error {
fmt.Printf("> %s\n", noOpMessage)
return nil
}
// Sync prints the no-op message and returns nil.
func (n *NoOp) Sync(_ context.Context, _ []string) error {
fmt.Printf("> %s\n", noOpMessage)
return nil
}
|