A CLI for managing declarative infrastructure.
Go to file
Ian Howell 61eecca7f3 Isolate unit tests by using temp directories
This commit changes several unit tests to set a "workspace" in a temp
directory. This completely isolates them from other tests as well as the
developer's environment.

Change-Id: Ifa1048c427dc3d69e15dae04318c7d8463b8f8e1
2019-11-12 15:37:29 -06:00
cmd Isolate unit tests by using temp directories 2019-11-12 15:37:29 -06:00
docs Merge "Initial Contributions and Developer Docs" 2019-11-07 20:56:39 +00:00
pkg Isolate unit tests by using temp directories 2019-11-12 15:37:29 -06:00
playbooks CI: Add a functional test for interacting with a existing k8s cluster 2019-07-09 21:04:15 +00:00
testutil Isolate unit tests by using temp directories 2019-11-12 15:37:29 -06:00
tools This removes golangci-lint as a go module dependency. 2019-10-30 09:26:42 -05:00
zuul.d Add Zull job for mirroring to GitHub 2019-07-16 16:50:49 -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
.golangci.yaml Initial commit for document pkg library 2019-10-04 14:22:26 -07:00
CONTRIBUTING.md Initial Contributions and Developer Docs 2019-11-07 10:48:32 -08:00
Dockerfile Move up to go 1.13.1 2019-10-04 15:31:45 +00:00
LICENSE Add LICENSE 2019-10-19 14:16:05 -05:00
Makefile Merge "Fix the `make cover` target" 2019-11-05 15:52:14 +00:00
README.md Rename module to reflect its new location 2019-07-01 12:15:29 -05:00
go.mod This updates the current unit tests for testify 2019-11-07 12:15:06 -06:00
go.sum This updates the current unit tests for testify 2019-11-07 12:15:06 -06:00
main.go Rename module to reflect its new location 2019-07-01 12:15:29 -05:00

README.md

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 opendev.org/airship/exampleplugin.

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

package main

import (
	"fmt"
	"os"

	"opendev.org/airship/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