From 2b28ab12f1dce41007a63d7366c56604750e9dfa Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 31 Mar 2019 19:54:17 +0000 Subject: [PATCH] Added docs for cli usage and adding new commands (#68) --- docs/content/doc/development/cli.md | 34 +++++++++ docs/content/doc/development/migrations.md | 8 +-- docs/content/doc/development/structure.md | 8 +++ docs/content/doc/usage/cli.md | 84 ++++++++++++++++++++++ 4 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 docs/content/doc/development/cli.md create mode 100644 docs/content/doc/usage/cli.md diff --git a/docs/content/doc/development/cli.md b/docs/content/doc/development/cli.md new file mode 100644 index 0000000000..9e9e6f2f3f --- /dev/null +++ b/docs/content/doc/development/cli.md @@ -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 + }, +} +{{}} \ No newline at end of file diff --git a/docs/content/doc/development/migrations.md b/docs/content/doc/development/migrations.md index 198331fe3f..9b574f6495 100644 --- a/docs/content/doc/development/migrations.md +++ b/docs/content/doc/development/migrations.md @@ -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. \ No newline at end of file diff --git a/docs/content/doc/development/structure.md b/docs/content/doc/development/structure.md index 372b26ba22..46607d0835 100644 --- a/docs/content/doc/development/structure.md +++ b/docs/content/doc/development/structure.md @@ -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, diff --git a/docs/content/doc/usage/cli.md b/docs/content/doc/usage/cli.md new file mode 100644 index 0000000000..02df87650f --- /dev/null +++ b/docs/content/doc/usage/cli.md @@ -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 >}} \ No newline at end of file