-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquerycmd.go
54 lines (44 loc) · 1.04 KB
/
querycmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (C) 2017, 2018 Damon Revoe. All rights reserved.
// Use of this source code is governed by the MIT
// license, which can be found in the LICENSE file.
package main
import (
"log"
"github.com/spf13/cobra"
)
func queryPackages(args []string) error {
ws, err := loadWorkspace()
if err != nil {
log.Fatal(err)
}
pi, err := readPackageDefinitions(ws.wp)
if err != nil {
log.Fatal(err)
}
if len(args) > 0 {
selection, err := packageRangesToFlatSelection(pi, args)
if err != nil {
return err
}
printListOfPackages(selection)
} else {
printListOfPackages(pi.orderedPackages)
}
return nil
}
// queryCmd represents the query command
var queryCmd = &cobra.Command{
Use: "query [package_range...]",
Short: "Print the list of packages found in $" + pkgPathEnvVar,
Run: func(_ *cobra.Command, args []string) {
if err := queryPackages(args); err != nil {
log.Fatal(err)
}
},
}
func init() {
rootCmd.AddCommand(queryCmd)
queryCmd.Flags().SortFlags = false
addPkgPathFlag(queryCmd)
addWorkspaceDirFlag(queryCmd)
}