cli

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2018 License: MIT Imports: 25 Imported by: 0

README

hcloud: Command-line interface for Hetzner Cloud

Build status

hcloud is a command-line interface for interacting with Hetzner Cloud.

asciicast

Installation

You can download pre-built binaries for Linux, FreeBSD, macOS, and Windows on the releases page.

On macOS, you can install hcloud via Homebrew:

brew install hcloud
Third-party packages

There are inofficial packages maintained by third-party users. Please note that these packages aren’t supported nor maintained by Hetzner Cloud and may not always be up-to-date. Downloading the binary or building from source is still the recommended install method.

Operating System Command
Arch Linux pacman -Syu hcloud
Build manually

If you have Go installed, you can build and install the hcloud program with:

go get -u github.com/hetznercloud/cli/cmd/hcloud

Getting Started

  1. Visit the Hetzner Cloud Console at console.hetzner.cloud, select your project, and create a new API token.

  2. Configure the hcloud program to use your token:

    hcloud context create my-project
    
  3. You’re ready to use the program. For example, to get a list of available server types, run:

    hcloud server-type list
    

See hcloud help for a list of commands.

Shell Completion

To enable shell completion, run one of the following commands (or better, add it to your .bashrc or .zshrc):

$ source <(hcloud completion bash)   # bash
$ source <(hcloud completion zsh)    # zsh

Using it in scripts

When using hcloud in scripts, it may be cumbersome to work with contexts. Instead of creating a context, you can set the token via the HCLOUD_TOKEN environment variable:

$ hcloud image list
hcloud: no active context or token (see `hcloud context --help`)
$ export HCLOUD_TOKEN=token
$ hcloud image list
ID   TYPE     NAME           DESCRIPTION    IMAGE SIZE   DISK SIZE   CREATED
1    system   ubuntu-16.04   Ubuntu 16.04   -            5 GB        1 month ago
2    system   debian-9       Debian 9.3     -            5 GB        1 month ago
3    system   centos-7       Centos 7.4     -            5 GB        1 month ago
4    system   fedora-27      Fedora 27      -            5 GB        1 month ago

Examples

List all servers
$ hcloud server list            
ID       NAME                    STATUS    IPV4
210216   test1                   running   78.46.122.12
210729   ubuntu-8gb-nbg1-dc3-1   running   94.130.177.158
Create a server
$ hcloud server create --name test --image debian-9 --type cx11 --ssh-key demo
   7s [====================================================================] 100%
Server 325211 created

License

MIT license

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfigPath string
View Source
var ErrConfigPathUnknown = errors.New("config file path unknown")
View Source
var Version = "was not built properly"

Version is set via compiler flags (see script/build.bash)

Functions

func MarshalConfig

func MarshalConfig(c *Config) ([]byte, error)

func NewRootCommand

func NewRootCommand(cli *CLI) *cobra.Command

Types

type CLI

type CLI struct {
	Token      string
	Endpoint   string
	Context    context.Context
	Config     *Config
	ConfigPath string

	RootCommand *cobra.Command
	// contains filtered or unexported fields
}

func NewCLI

func NewCLI() *CLI

func (*CLI) ActionProgress

func (c *CLI) ActionProgress(ctx context.Context, action *hcloud.Action) error

func (*CLI) Client

func (c *CLI) Client() *hcloud.Client

func (*CLI) ReadConfig

func (c *CLI) ReadConfig() error

func (*CLI) ReadEnv

func (c *CLI) ReadEnv()

func (*CLI) Terminal

func (c *CLI) Terminal() bool

Terminal returns whether the CLI is run in a terminal.

func (*CLI) WriteConfig

func (c *CLI) WriteConfig() error

type Config

type Config struct {
	Endpoint      string
	ActiveContext *ConfigContext
	Contexts      []*ConfigContext
}

func UnmarshalConfig

func UnmarshalConfig(data []byte) (*Config, error)

func (*Config) ContextByName

func (config *Config) ContextByName(name string) *ConfigContext

func (*Config) RemoveContext

func (config *Config) RemoveContext(context *ConfigContext)

type ConfigContext

type ConfigContext struct {
	Name  string
	Token string
}

type RawConfig

type RawConfig struct {
	ActiveContext string             `toml:"active_context,omitempty"`
	Contexts      []RawConfigContext `toml:"contexts"`
}

type RawConfigContext

type RawConfigContext struct {
	Name  string `toml:"name"`
	Token string `toml:"token"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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