MCPcopy
hub / github.com/TomWright/dasel / Run

Method Run

internal/cli/query.go:22–68  ·  view source on GitHub ↗
(ctx *Globals)

Source from the content-addressed store, hash-verified

20}
21
22func (c *QueryCmd) Run(ctx *Globals) error {
23 cfg, err := LoadConfig(c.ConfigPath)
24 if err != nil {
25 return err
26 }
27
28 if c.InFormat == "" && c.OutFormat == "" {
29 c.InFormat = cfg.DefaultFormat
30 c.OutFormat = cfg.DefaultFormat
31 }
32
33 if c.Query == "" && c.InFormat == "" && ctx.Stdin == nil {
34 return ErrNoArgsGiven
35 }
36
37 if c.Interactive {
38 return NewInteractiveCmd(c).Run(ctx)
39 }
40
41 o := runOpts{
42 Vars: c.Vars,
43 ExtReadWriteFlags: c.ExtReadWriteFlags,
44 ExtReadFlags: c.ExtReadFlags,
45 ExtWriteFlags: c.ExtWriteFlags,
46 InFormat: c.InFormat,
47 OutFormat: c.OutFormat,
48 Compact: c.Compact,
49 ReturnRoot: c.ReturnRoot,
50 Unstable: c.Unstable,
51 Query: c.Query,
52
53 ConfigPath: c.ConfigPath,
54
55 Stdin: ctx.Stdin,
56 }
57 outBytes, err := run(o)
58 if err != nil {
59 return err
60 }
61
62 _, err = ctx.Stdout.Write(outBytes)
63 if err != nil {
64 return fmt.Errorf("error writing output: %w", err)
65 }
66
67 return nil
68}

Callers

nothing calls this directly

Calls 4

LoadConfigFunction · 0.85
NewInteractiveCmdFunction · 0.85
runFunction · 0.85
WriteMethod · 0.65

Tested by

no test coverage detected