(ctx *Globals)
| 20 | } |
| 21 | |
| 22 | func (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 | } |
nothing calls this directly
no test coverage detected