A CLI for managing declarative infrastructure.
Go to file
Ian Howell 3cda375947 Remove dependency on k8s-code-generator
The deletions from the go.mod in this change were a relic of an earlier
change, where the k8s-code-generator was being used to generated client
code for Argo workflows. Now that Argo has been properly integrated into
the project, this is no longer needed.

These deletions were caught by a `go mod tidy`

Change-Id: I3e9f115dc31ef30dee59ddeeee513282bc555fcf
2019-07-01 12:57:29 -05:00
cmd Remove unused constant 2019-06-25 15:34:40 -05:00
docs Remove argo 2019-06-13 08:12:45 -05:00
pkg Zuul: Switch from travis to zuul 2019-07-01 11:00:26 -05:00
playbooks Zuul: Switch from travis to zuul 2019-07-01 11:00:26 -05:00
test Zuul: Switch from travis to zuul 2019-07-01 11:00:26 -05:00
tools Remove dependency on k8s-code-generator 2019-07-01 12:57:29 -05:00
zuul.d Zuul: Switch from travis to zuul 2019-07-01 11:00:26 -05:00
.gitignore Remove old .gitignores 2019-06-06 09:30:51 -05:00
.gitreview Gerrit: Add .gitreview file 2019-06-25 08:11:57 -05:00
Dockerfile Zuul: Switch from travis to zuul 2019-07-01 11:00:26 -05:00
go.mod Remove dependency on k8s-code-generator 2019-07-01 12:57:29 -05:00
go.sum Remove dependency on k8s-code-generator 2019-07-01 12:57:29 -05:00
main.go Add a convenience NewAirshipCTLCommand function 2019-06-07 14:06:37 -05:00
Makefile Zuul: Switch from travis to zuul 2019-07-01 11:00:26 -05:00
README.md Zuul: Switch from travis to zuul 2019-07-01 11:00:26 -05:00

airshipctl

Custom Plugins Tutorial

This tutorial walks through a very basic plugin for airshipctl. For a more involved example, see Plugin Support

The following steps will get you started with a very rudimentary example plugin for airshipctl. First, create a directory for your project outside of the GOPATH:

mkdir /tmp/example
cd /tmp/example

This project will need to be a go module. You can initialize a module named example with the following:

go mod init example

Note that modules are a relatively new feature added to Go, so you'll need to be running Go1.11 or greater. Also note that most modules will follow a naming schema that matches the remote version control system. A more realistice module name might look something like github.com/ian-howell/exampleplugin.

Next, create a file main.go and populate it with the following:

package main

import (
	"fmt"
	"os"

	"github.com/ian-howell/airshipctl/cmd"
	"github.com/spf13/cobra"
)

func main() {
	rootCmd, _, err := cmd.NewRootCmd(os.Stdout)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create root airshipctl command: %s\n", err.Error())
		os.Exit(1)
	}

	exampleCmd := &cobra.Command{
		Use:   "example",
		Short: "an example plugin",
		Run: func(cmd *cobra.Command, args []string) {
			fmt.Fprintln(os.Stdout, "Hello airshipctl!")
		},
	}

	rootCmd.AddCommand(exampleCmd)
	if err := rootCmd.Execute(); err != nil {
		fmt.Fprintf(os.Stderr, "Failure during execution: %s\n", err.Error())
		os.Exit(1)
	}
}

And finally, run the build command to download and compile airshipctl:

go build -o airshipctl

Now that you've built airshipctl, you can access your plugin with the following command:

./airshipctl example

You may have noticed that this example ignores the second return value from cmd.NewRootCmd. This value is a pointer to the AirshipCTLSettings, which contains various configuration details, such as the debug flag and the path to the config file*. A useful paradigm involves embedding this object into a custom ExampleSettings struct. This can be seen in the demo repo.

For a more involved example, see Plugin Support

* Work in progress