|
| 1 | +// |
| 2 | +// Author:: Salim Afiune Maya (<[email protected]>) |
| 3 | +// Copyright:: Copyright 2024, Lacework Inc. |
| 4 | +// License:: Apache License, Version 2.0 |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | + |
| 19 | +package cmd |
| 20 | + |
| 21 | +import ( |
| 22 | + "strings" |
| 23 | + |
| 24 | + "github.com/spf13/cobra" |
| 25 | +) |
| 26 | + |
| 27 | +var ( |
| 28 | + // grpcCmd is a hidden command that developers use to debug CDK components |
| 29 | + grpcCmd = &cobra.Command{ |
| 30 | + Use: "grpc", |
| 31 | + Hidden: true, |
| 32 | + Short: "Starts a CDK gRPC server (developer mode)", |
| 33 | + Args: cobra.NoArgs, |
| 34 | + RunE: func(_ *cobra.Command, _ []string) error { |
| 35 | + cli.OutputHuman("\nDevelopment mode for CDK components") |
| 36 | + cli.OutputHuman("\n===================================\n\n") |
| 37 | + cli.OutputHuman("When debugging a component, it might expect some environment variables and a\n") |
| 38 | + cli.OutputHuman("running gRPC server, this command starts the CDK server and shows the variables\n") |
| 39 | + cli.OutputHuman("that your component might need:\n\n") |
| 40 | + vars := cli.envs() |
| 41 | + cli.OutputHuman("export %s", strings.Join(vars, " \\\n ")) |
| 42 | + cli.OutputHuman("\n\n'Ctrl+c' to stop the server. ") |
| 43 | + return cli.Serve() |
| 44 | + }, |
| 45 | + } |
| 46 | +) |
| 47 | + |
| 48 | +func init() { |
| 49 | + rootCmd.AddCommand(grpcCmd) |
| 50 | +} |
0 commit comments