Added docs for cli usage and adding new commands (#68)
This commit is contained in:
parent
be5a17e993
commit
2b28ab12f1
4 changed files with 130 additions and 4 deletions
34
docs/content/doc/development/cli.md
Normal file
34
docs/content/doc/development/cli.md
Normal 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 >}}
|
|
@ -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:
|
To easily get a new id, run the following on any unix system:
|
||||||
|
|
||||||
```bash
|
{{< highlight bash >}}
|
||||||
date +%Y%m%d%H%M%S
|
date +%Y%m%d%H%M%S
|
||||||
```
|
{{< /highlight >}}
|
||||||
|
|
||||||
New migrations should be added via the `init()` function to the `migrations` variable.
|
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.
|
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
|
### Example
|
||||||
|
|
||||||
```go
|
{{< highlight golang >}}
|
||||||
package migration
|
package migration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -66,6 +66,6 @@ func init() {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
```
|
{{< /highlight >}}
|
||||||
|
|
||||||
You should always copy the changed parts of the struct you're changing when adding migraitons.
|
You should always copy the changed parts of the struct you're changing when adding migraitons.
|
|
@ -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.
|
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
|
### config
|
||||||
|
|
||||||
This package configures the config. It sets default values and sets up viper and tells it where to look for config files,
|
This package configures the config. It sets default values and sets up viper and tells it where to look for config files,
|
||||||
|
|
84
docs/content/doc/usage/cli.md
Normal file
84
docs/content/doc/usage/cli.md
Normal 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 >}}
|
Loading…
Add table
Reference in a new issue