Compare commits

..

1 Commits

Author SHA1 Message Date
Kurtis Van Gent
4e4821eb3e chore: example command 2026-01-29 20:26:21 +00:00
3 changed files with 38 additions and 42 deletions

36
cmd/invoke.go Normal file
View File

@@ -0,0 +1,36 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
func newInvokeCmd(root *Command) *cobra.Command {
return &cobra.Command{
Use: "invoke",
Short: "Invoke a tool",
Run: func(cmd *cobra.Command, args []string) {
invoke(root)
},
}
}
func invoke(cmd *Command) {
fmt.Println("Hello, World! Here is one of my flags" + cmd.cfg.Address)
}

View File

@@ -396,6 +396,8 @@ func NewCommand(opts ...Option) *Command {
// wrap RunE command so that we have access to original Command object
cmd.RunE = func(*cobra.Command, []string) error { return run(cmd) }
baseCmd.AddCommand(newInvokeCmd(cmd))
return cmd
}

View File

@@ -1,42 +0,0 @@
// Copyright 2025 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package util
import "fmt"
type ErrorCategory string
const (
CategoryAgent ErrorCategory = "AGENT_ERROR"
CategoryServer ErrorCategory = "SERVER_ERROR"
)
// ToolboxError is the interface all custom errors must satisfy
type ToolboxError interface {
error
}
// Agent Errors
type AgentError struct{ Msg string }
func (e *AgentError) Error() string { return e.Msg }
func (e *AgentError) Category() ErrorCategory { return CategoryAgent }
// Server Errors
type ServerError struct {
Msg string
Cause error
}
func (e *ServerError) Error() string { return fmt.Sprintf("%s: %v", e.Msg, e.Cause) }
func (e *ServerError) Category() ErrorCategory { return CategoryServer }