Skip to content

Commit 63dcfe5

Browse files
committedFeb 21, 2023
Add --details flag
1 parent d56a65e commit 63dcfe5

File tree

2 files changed

+33
-41
lines changed

2 files changed

+33
-41
lines changed
 

‎cmd/nix-search/main.go

+33-35
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var rootFlags struct {
3131
Name *string
3232
Advanced *string
3333
JSON *bool
34+
Details *bool
3435
}
3536

3637
func root(c *cobra.Command, args []string) {
@@ -73,10 +74,7 @@ func root(c *cobra.Command, args []string) {
7374
o, _ := os.Stdout.Stat()
7475
isTerminal := (o.Mode() & os.ModeCharDevice) == os.ModeCharDevice
7576

76-
showVersion := true
77-
showDescription := true
78-
showLicenses := true
79-
showHomepage := true
77+
showDetails := *rootFlags.Details
8078

8179
for _, pkg := range packages {
8280
// If asked to spit out json, just dump the packages directly
@@ -92,45 +90,44 @@ func root(c *cobra.Command, args []string) {
9290
fmt.Print(": ", programs)
9391
}
9492
fmt.Println()
95-
if showVersion {
96-
fmt.Printf(" version: %s\n", pkg.Version)
93+
if !showDetails {
94+
continue
9795
}
98-
if showDescription {
99-
d := ""
100-
if pkg.Description != nil {
101-
d = *pkg.Description
102-
}
103-
fmt.Printf(" description: %s\n", d)
96+
// version
97+
fmt.Printf(" version: %s\n", pkg.Version)
98+
// description
99+
d := ""
100+
if pkg.Description != nil {
101+
d = *pkg.Description
104102
}
105-
if showLicenses {
106-
fmt.Printf(" license:")
107-
if len(pkg.Licenses) == 1 {
108-
license := pkg.Licenses[0]
103+
fmt.Printf(" description: %s\n", d)
104+
// license
105+
fmt.Printf(" license:")
106+
if len(pkg.Licenses) == 1 {
107+
license := pkg.Licenses[0]
108+
txt := license.FullName
109+
if isTerminal && license.URL != nil {
110+
txt = escapes.Link(*license.URL, license.FullName)
111+
}
112+
fmt.Printf(" %s\n", txt)
113+
} else {
114+
fmt.Printf("\n")
115+
for _, license := range pkg.Licenses {
109116
txt := license.FullName
110117
if isTerminal && license.URL != nil {
111118
txt = escapes.Link(*license.URL, license.FullName)
112119
}
113-
fmt.Printf(" %s\n", txt)
114-
} else {
115-
fmt.Printf("\n")
116-
for _, license := range pkg.Licenses {
117-
txt := license.FullName
118-
if isTerminal && license.URL != nil {
119-
txt = escapes.Link(*license.URL, license.FullName)
120-
}
121-
fmt.Printf(" - %s\n", txt)
122-
}
120+
fmt.Printf(" - %s\n", txt)
123121
}
124122
}
125-
if showHomepage {
126-
fmt.Printf(" homepage:")
127-
if len(pkg.Homepage) == 1 {
128-
fmt.Printf(" %s\n", pkg.Homepage[0])
129-
} else {
130-
fmt.Printf("\n")
131-
for _, homepage := range pkg.Homepage {
132-
fmt.Printf(" - %s\n", homepage)
133-
}
123+
// homepage
124+
fmt.Printf(" homepage:")
125+
if len(pkg.Homepage) == 1 {
126+
fmt.Printf(" %s\n", pkg.Homepage[0])
127+
} else {
128+
fmt.Printf("\n")
129+
for _, homepage := range pkg.Homepage {
130+
fmt.Printf(" - %s\n", homepage)
134131
}
135132
}
136133
}
@@ -181,6 +178,7 @@ func main() {
181178
rootFlags.Name = rootCommand.Flags().StringP("name", "n", "", "search by attr name")
182179
rootFlags.Advanced = rootCommand.Flags().StringP("advanced", "a", "", "perform an advanced query string format search")
183180
rootFlags.JSON = rootCommand.Flags().BoolP("json", "j", false, "emit results in json-line format")
181+
rootFlags.Details = rootCommand.Flags().BoolP("details", "d", false, "show expanded details for each result")
184182

185183
if err := rootCommand.Execute(); err != nil {
186184
panic(err)

‎pkg/nixsearch/client.go

-6
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,6 @@ const (
154154
`
155155
)
156156

157-
/*
158-
nix-search this is the default query works just like the website
159-
nix-search -q this is the default query works just like the website
160-
nix-search --program gcloud # substring match on program entry
161-
nix-search --attr name # substring match on attribute name
162-
*/
163157
func ProgramQuery(query string) (string, error) {
164158
encQuery, err := json.Marshal(query)
165159
if err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.