Debian Codegraph @

exp/open/open.go

raw
1 // Package open provides functionality for opening files and URLs.
2 package open
3
4 import (
5 "context"
6 "errors"
7 "fmt"
8 )
9
10 // ErrNotSupported occurs when no ways to open a file are found.
11 var ErrNotSupported = errors.New("not supported")
12
13 // Open the given input.
14 func Open(ctx context.Context, input string) error {
15 return With(ctx, "", input)
16 }
17
18 // With opens the given input using the given app.
19 func With(ctx context.Context, app, input string) error {
20 cmd := buildCmd(ctx, app, input)
21 if cmd == nil {
22 return ErrNotSupported
23 }
24 out, err := cmd.CombinedOutput()
25 if err != nil {
26 return fmt.Errorf("open: %w: %s", err, string(out))
27 }
28 return nil
29 }