author | Mikael Berthe <mikael@lilotux.net> |
Sun, 23 Apr 2017 23:32:16 +0200 | |
changeset 13 | f862af8faf17 |
parent 0 | 5abace724584 |
child 45 | b58a7ea1aeb2 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright © 2017 Mikael Berthe <mikael@lilotux.net> |
2 |
// |
|
3 |
// Licensed under the MIT license. |
|
4 |
// Please see the LICENSE file is this directory. |
|
5 |
||
6 |
package cmd |
|
7 |
||
8 |
import ( |
|
9 |
"errors" |
|
10 |
"strings" |
|
11 |
||
12 |
"github.com/spf13/cobra" |
|
13 |
) |
|
14 |
||
15 |
var searchOpts struct { |
|
16 |
resolve bool |
|
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
17 |
//limit uint |
0 | 18 |
} |
19 |
||
20 |
// searchCmd represents the search command |
|
21 |
var searchCmd = &cobra.Command{ |
|
22 |
Use: "search [--resolve] STRING", |
|
23 |
Short: "Search for contents (accounts or statuses)", |
|
24 |
//Long: `TBW...`, |
|
25 |
RunE: searchRunE, |
|
26 |
} |
|
27 |
||
28 |
func init() { |
|
29 |
RootCmd.AddCommand(searchCmd) |
|
30 |
||
31 |
searchCmd.Flags().BoolVar(&searchOpts.resolve, "resolve", false, "Resolve non-local accounts") |
|
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
32 |
//searchCmd.Flags().UintVarP(&searchOpts.limit, "limit", "l", 0, "Limit number of results") |
0 | 33 |
} |
34 |
||
35 |
func searchRunE(cmd *cobra.Command, args []string) error { |
|
36 |
opt := searchOpts |
|
37 |
||
38 |
if len(args) == 0 { |
|
39 |
return errors.New("no search string provided") |
|
40 |
} |
|
41 |
||
42 |
if err := madonInit(true); err != nil { |
|
43 |
return err |
|
44 |
} |
|
45 |
||
46 |
results, err := gClient.Search(strings.Join(args, " "), opt.resolve) |
|
47 |
if err != nil { |
|
48 |
errPrint("Error: %s", err.Error()) |
|
49 |
return nil |
|
50 |
} |
|
51 |
||
52 |
p, err := getPrinter() |
|
53 |
if err != nil { |
|
54 |
return err |
|
55 |
} |
|
56 |
return p.PrintObj(results, nil, "") |
|
57 |
} |