|
| 1 | +// Copyright 2023 The Tekton Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package logs |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "os" |
| 20 | + |
| 21 | + "github.com/spf13/cobra" |
| 22 | + pb "github.com/tektoncd/results/proto/v1alpha2/results_go_proto" |
| 23 | + "github.com/tektoncd/results/tools/tkn-results/internal/flags" |
| 24 | + "github.com/tektoncd/results/tools/tkn-results/internal/format" |
| 25 | +) |
| 26 | + |
| 27 | +func ListCommand(params *flags.Params) *cobra.Command { |
| 28 | + opts := &flags.ListOptions{} |
| 29 | + |
| 30 | + cmd := &cobra.Command{ |
| 31 | + Use: `list [flags] <result parent> |
| 32 | +
|
| 33 | + <result parent>: Result parent name to query. This is typically "<namespace>/results/<result name>", but may vary depending on the API Server. "-" may be used as <result name> to query all Results for a given parent.`, |
| 34 | + Short: "List Records", |
| 35 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 36 | + resp, err := params.LogsClient.ListLogs(cmd.Context(), &pb.ListRecordsRequest{ |
| 37 | + Parent: args[0], |
| 38 | + Filter: opts.Filter, |
| 39 | + PageSize: opts.Limit, |
| 40 | + PageToken: opts.PageToken, |
| 41 | + }) |
| 42 | + if err != nil { |
| 43 | + fmt.Printf("ListRecords: %v\n", err) |
| 44 | + return err |
| 45 | + } |
| 46 | + return format.PrintProto(os.Stdout, resp, opts.Format) |
| 47 | + }, |
| 48 | + Args: cobra.ExactArgs(1), |
| 49 | + } |
| 50 | + |
| 51 | + flags.AddListFlags(opts, cmd) |
| 52 | + |
| 53 | + return cmd |
| 54 | +} |
0 commit comments