1
0

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,