Debian Codegraph @

internal/cli/interactive.go

raw symbols SCIP
1 package cliscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src go1.25 bytes/"
5 "fmtscip-go gomod github.com/golang/go/src go1.25 fmt/"
6 "ioscip-go gomod github.com/golang/go/src go1.25 io/"
7
8 "github.com/tomwright/dasel/v3/parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/"
9 )
10
11 func NewInteractiveCmdscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/NewInteractiveCmd().(queryCmd *QueryCmdscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/QueryCmd#) *InteractiveCmdscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd# {
12 return &InteractiveCmdscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#{
13 Varsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#Vars.: queryCmd.Varsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/QueryCmd#Vars.,
14 ExtReadWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ExtReadWriteFlags.: queryCmd.ExtReadWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/QueryCmd#ExtReadWriteFlags.,
15 ExtReadFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ExtReadFlags.: queryCmd.ExtReadFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/QueryCmd#ExtReadFlags.,
16 ExtWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ExtWriteFlags.: queryCmd.ExtWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/QueryCmd#ExtWriteFlags.,
17 InFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#InFormat.: queryCmd.InFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/QueryCmd#InFormat.,
18 OutFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#OutFormat.: queryCmd.OutFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/QueryCmd#OutFormat.,
19
20 Queryscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#Query.: queryCmd.Queryscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/QueryCmd#Query.,
21 }
22 }
23
24 type InteractiveCmdscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd# struct {
25 Varsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#Vars. variablesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/variables# `flag:"" name:"var" help:"Variables to pass to the query. E.g. --var foo=\"bar\" --var baz=json:file:./some/file.json"`
26 ExtReadWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ExtReadWriteFlags. extReadWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/extReadWriteFlags# `flag:"" name:"rw-flag" help:"Read/Write flag to customise parsing/output. Applies to read + write E.g. --rw-flag csv-delimiter=;"`
27 ExtReadFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ExtReadFlags. extReadWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/extReadWriteFlags# `flag:"" name:"read-flag" help:"Reader flag to customise parsing. E.g. --read-flag xml-mode=structured"`
28 ExtWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ExtWriteFlags. extReadWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/extReadWriteFlags# `flag:"" name:"write-flag" help:"Writer flag to customise output. E.g. --write-flag csv-delimiter=;"`
29 InFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#InFormat. string `flag:"" name:"in" short:"i" help:"The format of the input data."`
30 OutFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#OutFormat. string `flag:"" name:"out" short:"o" help:"The format of the output data."`
31
32 ConfigPathscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ConfigPath. string `name:"config" short:"c" help:"Path to config file" default:"~/dasel.yaml"`
33
34 Queryscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#Query. string `arg:"" help:"The query to execute." optional:"" default:""`
35 }
36
37 func (c *InteractiveCmdscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#) Runscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#Run().(ctx *Globalsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Globals#) error {
38 var stdInBytes []byte = nil
39
40 if ctx.Stdinscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Globals#Stdin. != nil {
41 var err error
42 stdInBytes, err = ioscip-go gomod github.com/golang/go/src go1.25 io/.ReadAllscip-go gomod github.com/golang/go/src go1.25 io/ReadAll().(ctx.Stdinscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Globals#Stdin.)
43 if err != nil {
44 return err
45 }
46 }
47
48 cfg, err := LoadConfigscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/LoadConfig().(c.ConfigPathscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ConfigPath.)
49 if err != nil {
50 return err
51 }
52
53 if c.InFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#InFormat. == "" && c.OutFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#OutFormat. == "" {
54 c.InFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#InFormat. = cfg.DefaultFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Config#DefaultFormat.
55 c.OutFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#OutFormat. = cfg.DefaultFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Config#DefaultFormat.
56 } else if c.InFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#InFormat. == "" {
57 c.InFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#InFormat. = c.OutFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#OutFormat.
58 } else if c.OutFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#OutFormat. == "" {
59 c.OutFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#OutFormat. = c.InFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#InFormat.
60 }
61
62 var runDasel interactiveDaselExecutorscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/interactiveDaselExecutor# = func(selector string, root bool, formatIn parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/.Formatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Format#, formatOut parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/.Formatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Format#, in string) (res string, err error) {
63 defer func() {
64 if r := recover(); r != nil {
65 err = fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("panic: %v", r)
66 }
67 }()
68 var stdIn *bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.Readerscip-go gomod github.com/golang/go/src go1.25 bytes/Reader#
69 if in != "" {
70 stdIn = bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25 bytes/NewReader().([]byte(in))
71 } else {
72 stdIn = bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25 bytes/NewReader().([]byte{})
73 }
74
75 o := runOptsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#{
76 Varsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#Vars.: c.Varsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#Vars.,
77 ExtReadWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#ExtReadWriteFlags.: c.ExtReadWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ExtReadWriteFlags.,
78 ExtReadFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#ExtReadFlags.: c.ExtReadFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ExtReadFlags.,
79 ExtWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#ExtWriteFlags.: c.ExtWriteFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ExtWriteFlags.,
80 InFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#InFormat.: formatIn.Stringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Format#String().(),
81 OutFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#OutFormat.: formatOut.Stringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Format#String().(),
82 ReturnRootscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#ReturnRoot.: root,
83 Unstablescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#Unstable.: true,
84 Queryscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#Query.: selector,
85
86 ConfigPathscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#ConfigPath.: c.ConfigPathscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#ConfigPath.,
87
88 Stdinscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/runOpts#Stdin.: stdIn,
89 }
90
91 outBytes, err := runscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/run().(o)
92 return string(outBytes), err
93 }
94
95 p, selectorFn := newInteractiveTeaProgramscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/newInteractiveTeaProgram().(string(stdInBytes), c.Queryscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#Query., parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/.Formatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Format#(c.InFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#InFormat.), parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/.Formatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Format#(c.OutFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/InteractiveCmd#OutFormat.), runDasel)
96
97 _, err = p.Runscip-go gomod github.com/charmbracelet/bubbletea v1.3.10 `github.com/charmbracelet/bubbletea`/Program#Run().()
98 if err != nil {
99 return err
100 }
101
102 if selectorFn != nil {
103 s := selectorFn()
104 if s != "" {
105 if _, err := fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Fprintf().(ctx.Stdoutscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Globals#Stdout., "%s\n", s); err != nil {
106 return fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("error writing output: %w", err)
107 }
108 }
109 }
110
111 return nil
112 }