cli

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cli defines plugin extension points for the csharg command. This allows to build extended capture service CLI clients that leverage the existing base implementation.

Extension Points

The following plugin “group” extension points are available (and also invoked in this general order):

  • SetupCLI: for adding (sub) commands and CLI args to the (in cobra parlance) “root” command.
  • CommandExamples: for adding (more) examples to particular commands, namely the “list” and “capture” commands. These plugin functions are invoked after all SetupCLI plugins have been called, so that all commands have been registered by the time the examples should be extended with even more examples.
  • BeforeCommand: for checking and doing things just before the command runs.
  • NewClient: for creating a suitable capture service client, depending on CLI args.

Simply put, the plugin mechanism used in csharg is compile-time only and allows so-called plugins to register functions (and interface implementations) in what is termed “groups”. The registered functions/interfaces then can be iterated over. Additionally, the plugin mechanism allows control over the ordering of plugins: for instance, this allows to register command examples to be picked up after the csharg base examples. For more details about the plugin mechanism, please refer to go-plugger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Examples

func Examples(command string) string

Examples collects all examples for the specified command from the registered plugins. The examples returned by plugins are always separate with empty lines, yet there isn't any trailing newline for the overall section.

Types

type BeforeCommand

type BeforeCommand func(*cobra.Command) error

BeforeCommand defines an exposed plugin symbol type for running checks after the command line args have been processed and before running the (chosen) command.

type CommandExamples

type CommandExamples func() map[string]string

CommandExamples defines an exposed symbol with CLI examples, indexed by a particular (sub) command, namely: “list” and “capture” at this time.

type NewClient

type NewClient func() (csharg.SharkTank, error)

NewClient defines an exposed plugin symbol type for returning a suitable capture client based on the CLI args. If a registered plugin factory isn't responsible, it must return a nil client as well as a nil error. If a factory returns a non-nil error, the attempt to find a suitable factory will be aborted and the returned error reported to the CLI user.

type SemVer

type SemVer func() string

SemVer defines an exposed plugin symbol type for returning (overriding) the CLI binary's semantic version. The first plugin will win.

type SetupCLI

type SetupCLI func(*cobra.Command)

SetupCLI defines an exposed plugin symbol type for adding “things” to a cobra root command (the csharg root command in particular).

Directories

Path Synopsis
Package command implements the common commands of the csharg CLI.
Package command implements the common commands of the csharg CLI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL