Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 1.39 KB

03-hq.md

File metadata and controls

33 lines (22 loc) · 1.39 KB

HQ container and setup

HQ as an object is meant as a single entry point of cops-hq setup, containing basic functionality like logging, executor and CLI setups. The HQ instance can be seen as a IoC container, which you will often pass around different objects and methods.

Basic usage of HQ container can be seen in main.go file in cmd/cops-hq. You will either use hq.New() or hq.NewQuiet() method, which will basically set up the commands.Executor in either chatty or quiet mode.

Keep only one instance of HQ around. Make sure to check out hq.HQ interface for more documentation.

Usual setup pattern with HQ

Usually, you will set up the application like this:

hq := hq.New("my-app", "0.0.1", "my-app.log")

infraCommand := hq.GetCli().AddBaseCommand("infrastructure", "Infrastructure command", "Example infrastructure command", nil)

infraCommand.AddCommand("create", ..., func() {
	// do stuff here, for example you can call the executor
	result, err := hq.GetExecutor().Execute("ssh user@server \"$RM_CMD\"")
	...
})

// this will start the parsing the os.Args given to the application, and execute the matching CLI command
hq.Run()

Dependency checking

Since cops-hq relies on that all the necessary tools are pre-installed, you can either use the hq.CheckToolingDependencies() method in your code, or call the in-built hq check-dependencies command on the console of your IaC app.