MCPcopy Index your code
hub / github.com/git-bug/git-bug / Resolve

Function Resolve

commands/select/select.go:45–87  ·  view source on GitHub ↗

Resolve first try to resolve an entity using the first argument of the command line. If it fails, it falls back to the select mechanism. Returns: - the entity if any - the new list of command line arguments with the entity prefix removed if it has been used - an error if the process failed

(repo *cache.RepoCache,
	typename string, namespace string, resolver Resolver[CacheT],
	args []string)

Source from the content-addressed store, hash-verified

43// has been used
44// - an error if the process failed
45func Resolve[CacheT cache.CacheEntity](repo *cache.RepoCache,
46 typename string, namespace string, resolver Resolver[CacheT],
47 args []string) (CacheT, []string, error) {
48 // At first, try to use the first argument as an entity prefix
49 if len(args) > 0 {
50 cached, err := resolver.ResolvePrefix(args[0])
51
52 if err == nil {
53 return cached, args[1:], nil
54 }
55
56 if !entity.IsErrNotFound(err) {
57 return *new(CacheT), nil, err
58 }
59 }
60
61 // first arg is not a valid entity prefix, we can safely use the preselected entity if any
62
63 cached, err := selected(repo, resolver, namespace)
64
65 // selected entity is invalid
66 if entity.IsErrNotFound(err) {
67 // we clear the selected bug
68 err = Clear(repo, namespace)
69 if err != nil {
70 return *new(CacheT), nil, err
71 }
72 return *new(CacheT), nil, NewErrNoValidId(typename)
73 }
74
75 // another error when reading the entity
76 if err != nil {
77 return *new(CacheT), nil, err
78 }
79
80 // entity is successfully retrieved
81 if cached != nil {
82 return *cached, args, nil
83 }
84
85 // no selected bug and no valid first argument
86 return *new(CacheT), nil, NewErrNoValidId(typename)
87}
88
89func selectFileName(namespace string) string {
90 return filepath.Join("select", namespace)

Callers 1

TestSelectFunction · 0.70

Calls 5

IsErrNotFoundFunction · 0.92
selectedFunction · 0.85
ClearFunction · 0.85
NewErrNoValidIdFunction · 0.85
ResolvePrefixMethod · 0.65

Tested by 1

TestSelectFunction · 0.56