Coder Social home page Coder Social logo

cli's Introduction

hcloud: Command-line interface for Hetzner Cloud

Release Go Version CI Build codecov

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 and Linux, you can install hcloud via Homebrew:

brew install hcloud

On Windows, you can install hcloud via Scoop

scoop install hcloud

Third-party packages

There are unofficial 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.

Build manually

If you have Go installed, you can build and install the latest version of hcloud with:

go install github.com/hetznercloud/cli/cmd/hcloud@latest

Binaries built in this way do not have the correct version embedded. Use our prebuilt binaries or check out .goreleaser.yml to learn how to embed it yourself.

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

hcloud provides completions for various shells.

Bash

To load completions into the current shell execute:

source <(hcloud completion bash)

In order to make the completions permanent, append the line above to your .bashrc.

Zsh

If shell completions are not already enabled for your environment need to enable them. Add the following line to your ~/.zshrc file:

autoload -Uz compinit; compinit

To load completions for each session execute the following commands:

mkdir -p ~/.config/hcloud/completion/zsh
hcloud completion zsh > ~/.config/hcloud/completion/zsh/_hcloud

Finally, add the following line to your ~/.zshrc file, before you call the compinit function:

fpath+=(~/.config/hcloud/completion/zsh)

In the end your ~/.zshrc file should contain the following two lines in the order given here.

fpath+=(~/.config/hcloud/completion/zsh)
#  ... anything else that needs to be done before compinit
autoload -Uz compinit; compinit
# ...

You will need to start a new shell for this setup to take effect.

Fish

To load completions into the current shell execute:

hcloud completion fish | source

In order to make the completions permanent execute once:

 hcloud completion fish > ~/.config/fish/completions/hcloud.fish

PowerShell:

To load completions into the current shell execute:

PS> hcloud completion powershell | Out-String | Invoke-Expression

To load completions for every new session, run and source this file from your PowerShell profile.

PS> hcloud completion powershell > hcloud.ps1

Output configuration

You can control output via the -o option:

  • For list commands, you can specify -o noheader to omit the table header.

  • For list commands, you can specify -o columns=id,name to only show certain columns in the table.

  • For describe commands, you can specify -o json to get a JSON representation of the resource. The schema is identical to those in the Hetzner Cloud API which are documented at docs.hetzner.cloud.

  • For create commands, you can specify -o json to get a JSON representation of the API response. API responses are documented at docs.hetzner.cloud. In contrast to describe commands, create commands can return extra information, for example the initial root password of a server.

  • For describe commands, you can specify -o format={{.ID}} to format output according to the given Go template. The template’s input is the resource’s corresponding struct in the hcloud-go library.

Configuring hcloud

The hcloud CLI tool can be configured using following methods:

  1. Configuration file
  2. Environment variables
  3. Command line flags

A higher number means a higher priority. For example, a command line flag will always override an environment variable.

The configuration file is located at ~/.config/hcloud/cli.toml by default (On Windows: %APPDATA%\hcloud\cli.toml). You can change the location by setting the HCLOUD_CONFIG environment variable or the --config flag. The configuration file stores global preferences, the currently active context, all contexts and context-specific preferences. Contexts always store a token and can optionally have additional preferences which take precedence over the globally set preferences.

However, a config file is not required. If no config file is found, the CLI will use the default configuration. Overriding options using environment variables allows the hcloud CLI to function in a stateless way. For example, setting HCLOUD_TOKEN is already enough in many cases.

You can use the hcloud config command to manage your configuration, for example to get, list, set and unset configuration options and preferences. You can view a list of all available options and preferences by running hcloud config --help.

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 cx22 --ssh-key demo
   7s [====================================================================] 100%
Server 325211 created

License

MIT license

cli's People

Contributors

apricote avatar cedi avatar dependabot[bot] avatar eike-fokken avatar fhofherr avatar gadelkareem avatar github-actions[bot] avatar hcloud-bot avatar jooola avatar joto avatar kranurag7 avatar ktomk avatar lkaemmerling avatar mfrister avatar minus7 avatar n9v9 avatar patrickschaffrath avatar phil-davis avatar philippgille avatar phm07 avatar renovate[bot] avatar samcday avatar suzuki-shunsuke avatar thcyron avatar thetechnick avatar tomsiewert avatar uskudnik avatar vincentvanlaer avatar wheinze avatar wullsnpaxbwzgydyyhwtkkspeqoayxxyhoisqhf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cli's Issues

Fix datetime output

$ hcloud image describe ubuntu-16.04 
...
Created:	2018-01-15 11:34:45 +0000 +0000 (1 week ago)
...

Having the offset printed twice looks odd. We should print it either as UTC or in the user’s local time.

hcloud floating-ip create help: Show valid types. Consider default value

>hcloud floating-ip create --help
Create a Floating IP

Usage:
  hcloud floating-ip create FLAGS

Flags:
      --description string     Description
  -h, --help                   help for create
      --home-location string   Home location
      --server string          Server to assign Floating IP to
      --type string            Type

For type we should show the valid choices (ipv4, ipv6) in the help text.

How about making ipv4 the default for type?

Feature Idea: Option to set reverse lookup to instance name

In the case of spawning a lot of instances, it may be useful to set the reverse lookup to the instance name, if the instance name is a DNS hostname.

This would prevent to change in XYZ instances manually in the console or with the API.

Context handling still not use friendly

Most users seem to assume that after creating a context it is automatically used. Maybe we can satisfy this expectation?

Even if we do not decide to auto-select recently created context we should print a message after context creation which clearly indicates what has happened:

Either

  • new context created but you will need to run hcloud context x use to activate or
  • new context created and it was automatically activated

zsh auto-complete is partialy borken

Just builded the client on a ubuntu-16.04 machine (while being connectec via ssh) with golang-1.9 the auto-completion sometimes fails (for example auto completing the ssh-key inside the server create) will lead to the following error:
_handle_flag:27: bad math expression: illegal character: ^[

hcloud image list: Add optional argument for image type

Right now hcloud image list seems to show images of all types. We should consider adding an optional argument --type which enables you to only list images of a certain type, e.g.

hcloud image list --type system will only show system images

Progress bar not shown correctly on Windows

On Windows, the progress bar is only shown correctly when the prompt is slightly larger than the default size (in width). Otherwise the progress bar is printed multiple times.

screenshot 145 eingabeaufforderung

Release v1.0.0

  • Pin github.com/hetznercloud/hcloud-go to v1.0.0 in Gopkg.toml
  • Set Version constant to 1.0.0
  • Update hcloud-go once v1.0.0 of hcloud-go is re-tagged

Optional

  • Add completions to Homebrew formula
  • Get the Homebrew formula into the main library

Output configuration

We want to be able to control how output is formatted.

For example, we want to disable printing the column names (first line) to be able to do things like:

$ hcloud server list | wc -l
5

Or to specify which columns are printed:

$ hcloud server list
ID
1
2
3

In the future we might also want to support other output formats (JSON, YAML).

Proposal

Output is completely controlled via the -o option which can be specified multiple times with different values. A value is either just a key key or a key-value pair key=value.

Examples

To disable printing column names:

$ hcloud -o nocolumns server list

To only print the ID and name columns and sort by name:

$ hcloud -o columns=id,name -o sort=name:desc server list

To output JSON:

$ hcloud -o format=json server list

The option format=table is the default output format.

Update readme

An asciinema showing the CLI in action would be nice.

Show prefix for IPv6 addresses

$ hcloud floating-ip list     
ID   TYPE   DESCRIPTION   IP                   HOME   SERVER   DNS
49   ipv6   dsds          2a01:4f8:1c17:2c::   fsn1   -        -

Fix it everywhere.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.