Debian Codegraph @

internal/cli/man.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 "osscip-go gomod github.com/golang/go/src go1.25 os/"
7 "strconvscip-go gomod github.com/golang/go/src go1.25 strconv/"
8 "stringsscip-go gomod github.com/golang/go/src go1.25 strings/"
9 "text/templatescip-go gomod github.com/golang/go/src go1.25 `text/template`/"
10 "timescip-go gomod github.com/golang/go/src go1.25 time/"
11
12 "github.com/alecthomas/kongscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/"
13 "github.com/tomwright/dasel/v3/internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal`/"
14 )
15
16 type ManCmdscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/ManCmd# struct{}
17
18 type manFlagscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag# struct {
19 Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#Name. string
20 Shortscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#Short. string
21 Helpscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#Help. string
22 }
23
24 type manSubcommandscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manSubcommand# struct {
25 Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manSubcommand#Name. string
26 Helpscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manSubcommand#Help. string
27 Flagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manSubcommand#Flags. []manFlagscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#
28 }
29
30 type manDatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData# struct {
31 Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#Name. string
32 Descriptionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#Description. string
33 Versionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#Version. string
34 Datescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#Date. string
35 Subcommandsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#Subcommands. []manSubcommandscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manSubcommand#
36 GlobalFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#GlobalFlags. []manFlagscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#
37 QueryFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#QueryFlags. []manFlagscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#
38 }
39
40 const dateFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/dateFormat. = "2006-01-02"
41
42 func getReproducibleDatescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/getReproducibleDate().() (string, error) {
43 sourceDateEpochEnv, ok := osscip-go gomod github.com/golang/go/src go1.25 os/.LookupEnvscip-go gomod github.com/golang/go/src go1.25 os/LookupEnv().("SOURCE_DATE_EPOCH")
44
45 // Fallback to current date if SOURCE_DATE_EPOCH is unset or empty.
46 if !ok || sourceDateEpochEnv == "" {
47 return timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now().().Formatscip-go gomod github.com/golang/go/src go1.25 time/Time#Format().(dateFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/dateFormat.), nil
48 }
49
50 sde, err := strconvscip-go gomod github.com/golang/go/src go1.25 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.25 strconv/ParseInt().(sourceDateEpochEnv, 10, 64)
51 if err != nil {
52 return "", fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("invalid SOURCE_DATE_EPOCH: %q", sourceDateEpochEnv)
53 }
54
55 return timescip-go gomod github.com/golang/go/src go1.25 time/.Unixscip-go gomod github.com/golang/go/src go1.25 time/Unix().(sde, 0).UTCscip-go gomod github.com/golang/go/src go1.25 time/Time#UTC().().Formatscip-go gomod github.com/golang/go/src go1.25 time/Time#Format().(dateFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/dateFormat.), nil
56 }
57
58 func extractManDatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/extractManData().(k *kongscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/.Kongscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Kong#) manDatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData# {
59 app := k.Modelscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Kong#Model.
60
61 data := manDatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#{
62 Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#Name.: stringsscip-go gomod github.com/golang/go/src go1.25 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.25 strings/ToUpper().(app.Namescip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Node#Name.),
63 Descriptionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#Description.: app.Helpscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Node#Help.,
64 Versionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#Version.: internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal`/.Versionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal`/Version.,
65 }
66
67 for _, flag := range app.Flagsscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Node#Flags. {
68 if flag.Hiddenscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Flag#Hidden. {
69 continue
70 }
71 mf := manFlagscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#{
72 Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#Name.: flag.Namescip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Value#Name.,
73 Helpscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#Help.: flag.Helpscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Value#Help.,
74 }
75 if flag.Shortscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Flag#Short. != 0 {
76 mf.Shortscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#Short. = string(flag.Shortscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Flag#Short.)
77 }
78 data.GlobalFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#GlobalFlags. = append(data.GlobalFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#GlobalFlags., mf)
79 }
80
81 for _, child := range app.Childrenscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Node#Children. {
82 if child.Hiddenscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Node#Hidden. {
83 continue
84 }
85 if child.Typescip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Node#Type. != kongscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/.CommandNodescip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/CommandNode. {
86 continue
87 }
88 sub := manSubcommandscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manSubcommand#{
89 Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manSubcommand#Name.: child.Namescip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Node#Name.,
90 Helpscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manSubcommand#Help.: child.Helpscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Node#Help.,
91 }
92 for _, flag := range child.Flagsscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Node#Flags. {
93 if flag.Hiddenscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Flag#Hidden. {
94 continue
95 }
96 mf := manFlagscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#{
97 Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#Name.: flag.Namescip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Value#Name.,
98 Helpscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#Help.: flag.Helpscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Value#Help.,
99 }
100 if flag.Shortscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Flag#Short. != 0 {
101 mf.Shortscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manFlag#Short. = string(flag.Shortscip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Flag#Short.)
102 }
103 sub.Flagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manSubcommand#Flags. = append(sub.Flagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manSubcommand#Flags., mf)
104 }
105 if child.Namescip-go gomod github.com/alecthomas/kong v1.14.0 `github.com/alecthomas/kong`/Node#Name. == "query" {
106 data.QueryFlagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#QueryFlags. = sub.Flagsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manSubcommand#Flags.
107 }
108 data.Subcommandsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#Subcommands. = append(data.Subcommandsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#Subcommands., sub)
109 }
110
111 return data
112 }
113
114 func (c *ManCmdscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/ManCmd#) Runscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/ManCmd#Run().(ctx *Globalsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Globals#) error {
115 data := extractManDatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/extractManData().(ctx.Kongscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Globals#Kong.)
116
117 date, err := getReproducibleDatescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/getReproducibleDate().()
118 if err != nil {
119 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 extracting man page data: %w", err)
120 }
121 data.Datescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manData#Date. = date
122
123 tmpl, err := templatescip-go gomod github.com/golang/go/src go1.25 `text/template`/.Newscip-go gomod github.com/golang/go/src go1.25 `text/template`/New().("man").Funcsscip-go gomod github.com/golang/go/src go1.25 `text/template`/Template#Funcs().(templatescip-go gomod github.com/golang/go/src go1.25 `text/template`/.FuncMapscip-go gomod github.com/golang/go/src go1.25 `text/template`/FuncMap#{
124 "toLower": stringsscip-go gomod github.com/golang/go/src go1.25 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25 strings/ToLower().,
125 "toUpper": stringsscip-go gomod github.com/golang/go/src go1.25 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.25 strings/ToUpper().,
126 }).Parsescip-go gomod github.com/golang/go/src go1.25 `text/template`/Template#Parse().(manPageTmplscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manPageTmpl.)
127 if err != nil {
128 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 parsing man page template: %w", err)
129 }
130
131 var buf bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25 bytes/Buffer#
132 if err := tmpl.Executescip-go gomod github.com/golang/go/src go1.25 `text/template`/Template#Execute().(&buf, data); err != nil {
133 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 executing man page template: %w", err)
134 }
135
136 _, err = ctx.Stdoutscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Globals#Stdout..Writescip-go gomod github.com/golang/go/src go1.25 io/Writer#Write().(buf.Bytesscip-go gomod github.com/golang/go/src go1.25 bytes/Buffer#Bytes().())
137 return err
138 }
139
140 const manPageTmplscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/manPageTmpl. = `.TH {{.Name}} 1 "{{.Date}}" "{{.Version}}" "{{.Name}} Manual"
141 .SH NAME
142 {{.Name | toLower}} \- {{.Description}}
143 .SH SYNOPSIS
144 .B {{.Name | toLower}}
145 [\fIflags\fR]
146 [\fIquery\fR]
147 .br
148 .B {{.Name | toLower}}
149 \fIcommand\fR
150 [\fIflags\fR]
151 .SH DESCRIPTION
152 .B {{.Name | toLower}}
153 is a command-line tool for querying and modifying data structures.
154 It supports multiple data formats including JSON, YAML, TOML, CSV, XML, and KDL.
155 .SH COMMANDS
156 {{range .Subcommands}}.TP
157 .B {{.Name}}
158 {{.Help}}
159 {{end}}
160 .SH OPTIONS
161 The following options are available for the default \fBquery\fR command:
162 {{range .QueryFlags}}.TP
163 {{if .Short}}\fB\-{{.Short}}\fR, {{end}}\fB\-\-{{.Name}}\fR
164 {{.Help}}
165 {{end}}
166 .SH GLOBAL OPTIONS
167 {{range .GlobalFlags}}.TP
168 {{if .Short}}\fB\-{{.Short}}\fR, {{end}}\fB\-\-{{.Name}}\fR
169 {{.Help}}
170 {{end}}{{range .Subcommands}}{{if .Flags}}
171 .SH {{.Name | toUpper}} OPTIONS
172 {{range .Flags}}.TP
173 {{if .Short}}\fB\-{{.Short}}\fR, {{end}}\fB\-\-{{.Name}}\fR
174 {{.Help}}
175 {{end}}{{end}}{{end}}
176 .SH EXAMPLES
177 .TP
178 Query JSON from stdin:
179 echo '{"name": "Tom"}' | {{.Name | toLower}} 'name'
180 .TP
181 Convert JSON to YAML:
182 echo '{"name": "Tom"}' | {{.Name | toLower}} -i json -o yaml
183 .TP
184 Query with compact output:
185 echo '{"name": "Tom"}' | {{.Name | toLower}} -i json -o json --compact
186 .SH SEE ALSO
187 .UR https://daseldocs.tomwright.me
188 Dasel documentation
189 .UE
190 `