Added docs for cli usage and adding new commands (#68)

This commit is contained in:
konrad 2019-03-31 19:54:17 +00:00 committed by Gitea
parent be5a17e993
commit 2b28ab12f1
4 changed files with 130 additions and 4 deletions

View file

@ -0,0 +1,34 @@
---
date: "2019-03-31:00:00+01:00"
title: "Adding new cli commands"
draft: false
type: "doc"
menu:
sidebar:
parent: "development"
---
# Adding new cli commands
All cli-related functions are located in `pkg/cmd`.
Each cli command usually calls a function in another package.
For example, the `vikunja migrate` command calls `migration.Migrate()`.
Vikunja uses the amazing [cobra](https://github.com/spf13/cobra) library for its cli.
Please refer to its documentation for informations about how to use flags etc.
To add a new cli command, add something like the following:
{{< highlight golang >}}
func init() {
rootCmd.AddCommand(myCmd)
}
var myCmd = &cobra.Command{
Use: "My-command",
Short: "A short description about your command.",
Run: func(cmd *cobra.Command, args []string) {
// Call other functions
},
}
{{</ highlight >}}

View file

@ -25,9 +25,9 @@ and a more in-depth description of what the migration actually does.
To easily get a new id, run the following on any unix system:
```bash
{{< highlight bash >}}
date +%Y%m%d%H%M%S
```
{{< /highlight >}}
New migrations should be added via the `init()` function to the `migrations` variable.
All migrations are sorted before being executed, since `init()` does not guarantee the order.
@ -37,7 +37,7 @@ to ensure it will be created on new installations.
### Example
```go
{{< highlight golang >}}
package migration
import (
@ -66,6 +66,6 @@ func init() {
},
})
}
```
{{< /highlight >}}
You should always copy the changed parts of the struct you're changing when adding migraitons.

View file

@ -51,6 +51,14 @@ This is where most of the magic happens. Most packages with actual code are loca
This folder holds a simple caldav implementation which is responsible for returning the caldav feature.
### cmd
This package contains all cli-related files and functions.
To learn more about how to add a new command, see [the cli docs]({{< ref "cli.md">}}).
To learn more about how to use this cli, see [the cli usage docs]({{< ref "../usage/cli.md">}}).
### config
This package configures the config. It sets default values and sets up viper and tells it where to look for config files,

View file

@ -0,0 +1,84 @@
---
date: "2019-03-31:00:00+01:00"
title: "CLI"
draft: false
type: "doc"
menu:
sidebar:
parent: "usage"
---
# Command line interface
You can interact with Vikunja using its `cli` interface.
The following commands are available:
* [help](#help)
* [migrate](#migrate)
* [version](#version)
* [web](#web)
If you don't specify a command, the [`web`](#web) command will be executed.
All commands use the same standard [config file]({{< ref "../setup/config.md">}}).
### `help`
Shows more detailed help about any command.
Usage:
{{< highlight bash >}}
$ vikunja help [command]
{{< /highlight >}}
### `migrate`
Run all database migrations which didn't already run.
Usage:
{{< highlight bash >}}
$ vikunja migrate [flags]
$ vikunja migrate [command]
{{< /highlight >}}
#### `migrate list`
Shows a list with all database migrations.
Usage:
{{< highlight bash >}}
$ vikunja migrate list
{{< /highlight >}}
#### `migrate rollback`
Roll migrations back until a certain point.
Usage:
{{< highlight bash >}}
$ vikunja migrate rollback [flags]
{{< /highlight >}}
Flags:
* `-n`, `--name` string: The id of the migration you want to roll back until.
### `version`
Prints the version of Vikunja.
This is either the semantic version (something like `0.7`) or version + git commit hash.
Usage:
{{< highlight bash >}}
$ vikunja version
{{< /highlight >}}
### `web`
Starts Vikunja's REST api server.
Usage:
{{< highlight bash >}}
$ vikunja web
{{< /highlight >}}