Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 346004e

Browse files
author
Mathias Lindholm
authored
Rewrite docs generation (#58)
* Rewrite the docs generation script * Add examples and update descriptions * Add `projects list` subcommand * Generate docs * Update short descriptions * Add aliases * Improve list formatting * Generate aliases into docs
1 parent 8987278 commit 346004e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+577
-470
lines changed

cmd/annotate.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import (
1313
)
1414

1515
var annotateCmd = &cobra.Command{
16-
Use: "annotate [<input file>] [<app id>]",
17-
Example: `speechly annotate -a <app_id> --input input.txt
18-
speechly annotate -a <app_id> --input input.txt > output.txt
19-
speechly annotate -a <app_id> --reference-date 2021-01-20 --input input.txt > output.txt
20-
21-
To evaluate already deployed Speechly app, you need a set of evaluation examples that users of your application might say.`,
22-
Short: "Create SAL annotations for a list of examples using Speechly.",
23-
Args: cobra.RangeArgs(0, 1),
16+
Use: "annotate",
17+
Short: "Create SAL annotations for a list of examples using Speechly",
18+
Long: "To evaluate already deployed Speechly app, you need a set of evaluation examples that users of your application might say.",
19+
Example: `speechly annotate input.txt <app_id>
20+
speechly annotate --app <app_id> --input input.txt > output.txt
21+
speechly annotate --app <app_id> --reference-date 2021-01-20 --input input.txt > output.txt`,
22+
Args: cobra.RangeArgs(0, 1),
2423
PreRunE: func(cmd *cobra.Command, args []string) error {
2524
appId, err := cmd.Flags().GetString("app")
2625
if err != nil {
@@ -108,7 +107,7 @@ To evaluate already deployed Speechly app, you need a set of evaluation examples
108107

109108
func init() {
110109
RootCmd.AddCommand(annotateCmd)
111-
annotateCmd.Flags().StringP("app", "a", "", "Application to evaluate. Can be given as the first positional argument.")
110+
annotateCmd.Flags().StringP("app", "a", "", "Application to evaluate. Can be given as the second positional argument.")
112111
annotateCmd.Flags().StringP("input", "i", "", "Evaluation utterances, separated by newline, if not provided, read from stdin. Can be given as the first positional argument.")
113112
annotateCmd.Flags().StringP("output", "o", "", "Where to store annotated utterances, if not provided, print to stdout.")
114113
annotateCmd.Flags().StringP("reference-date", "r", "", "Reference date in YYYY-MM-DD format, if not provided use current date.")

cmd/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func waitForAppStatus(cmd *cobra.Command, configClient configv1.ConfigAPIClient,
5858
if err != nil {
5959
log.Fatalf("Failed to refresh app %s: %s", appId, err)
6060
}
61-
cmd.Printf("Status:\t%s", app.App.Status)
61+
cmd.Printf("Status: %s", app.App.Status)
6262
switch app.App.Status {
6363
case configv1.App_STATUS_NEW:
6464
cmd.Printf(", queued (%d jobs before this)", app.App.QueueSize)

cmd/config.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ import (
1414
)
1515

1616
var configCmd = &cobra.Command{
17-
Use: "projects",
18-
Aliases: []string{"config"},
17+
Use: "projects [command]",
18+
Aliases: []string{"project", "config"},
1919
Short: "Manage API access to Speechly projects",
20+
Args: cobra.NoArgs,
21+
}
22+
23+
var validName = regexp.MustCompile(`[^A-Za-z0-9]+`)
24+
25+
var configListCmd = &cobra.Command{
26+
Use: "list",
27+
Aliases: []string{"ls"},
28+
Short: "List known projects",
2029
Run: func(cmd *cobra.Command, args []string) {
2130
conf := clients.GetConfig(cmd.Context())
2231
cmd.Printf("Settings file used: %s\n", viper.ConfigFileUsed())
@@ -38,12 +47,12 @@ var configCmd = &cobra.Command{
3847
},
3948
}
4049

41-
var validName = regexp.MustCompile(`[^A-Za-z0-9]+`)
42-
4350
var configAddCmd = &cobra.Command{
44-
Use: "add [apikey]",
51+
Use: "add",
4552
Short: "Add access to a pre-existing project",
46-
Args: cobra.RangeArgs(0, 1),
53+
Example: `speechly projects add <api_token>
54+
speechly projects add --apikey <api_token>`,
55+
Args: cobra.RangeArgs(0, 1),
4756
PreRunE: func(cmd *cobra.Command, args []string) error {
4857
name, _ := cmd.Flags().GetString("name")
4958
if name != "" && validName.MatchString(name) {
@@ -134,8 +143,10 @@ var configAddCmd = &cobra.Command{
134143
}
135144

136145
var configRemoveCmd = &cobra.Command{
137-
Use: "remove",
138-
Short: "Remove access to a project",
146+
Use: "remove",
147+
Aliases: []string{"rm"},
148+
Short: "Remove access to a project",
149+
Example: `speechly projects remove --name <project_name>`,
139150
PreRunE: func(cmd *cobra.Command, args []string) error {
140151
name, _ := cmd.Flags().GetString("name")
141152
if err := ensureContextExists(cmd.Context(), name); err != nil {
@@ -164,8 +175,11 @@ var configRemoveCmd = &cobra.Command{
164175
}
165176

166177
var configUseCmd = &cobra.Command{
167-
Use: "use",
168-
Short: "Select the default project used",
178+
Use: "use",
179+
Aliases: []string{"switch"},
180+
Short: "Select the default project used",
181+
Example: `speechly projects use
182+
speechly projects use --name <project_name>`,
169183
Run: func(cmd *cobra.Command, args []string) {
170184
previousContext := viper.Get("current-context")
171185
name, _ := cmd.Flags().GetString("name")
@@ -220,6 +234,8 @@ func ensureContextExists(ctx context.Context, name string) error {
220234
}
221235

222236
func init() {
237+
configCmd.AddCommand(configListCmd)
238+
223239
configAddCmd.Flags().String("apikey", "", "API token, created in Speechly Dashboard. Can also be given as the sole positional argument.")
224240
configAddCmd.Flags().String("name", "", "An unique name for the project. If not given the project name configured in Speechly Dashboard will be used.")
225241
configAddCmd.Flags().String("host", "api.speechly.com", "API address")

cmd/convert.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ func (u ConvertWriter) Write(data []byte) (n int, err error) {
2727
}
2828

2929
var convertCmd = &cobra.Command{
30-
Use: "convert [-l language] <input_file>",
31-
Example: `speechly convert my-alexa-skill.json
32-
speechly convert -l en-US my-alexa-skill.json`,
30+
Use: "convert",
3331
Short: "Converts an Alexa Interaction Model in JSON format to a Speechly configuration",
34-
Args: cobra.ExactArgs(1),
32+
Example: `speechly convert my-alexa-skill.json
33+
speechly convert --language en-US my-alexa-skill.json`,
34+
Args: cobra.ExactArgs(1),
3535
Run: func(cmd *cobra.Command, args []string) {
3636
ctx := cmd.Context()
3737
language, _ := cmd.Flags().GetString("language")

cmd/create.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ import (
1313
)
1414

1515
var createCmd = &cobra.Command{
16-
Use: "create [<application name>]",
17-
Example: `speechly create "My App"
18-
speechly create --name "My App" --output-dir /foo/bar
19-
`,
16+
Use: "create",
2017
Short: "Create a new application in the current project",
2118
Long: "Creates a new application in the current project and a config file in the current working directory.",
22-
Args: cobra.RangeArgs(0, 1),
19+
Example: `speechly create "My App"
20+
speechly create --name "My App" --output-dir /foo/bar`,
21+
Args: cobra.RangeArgs(0, 1),
2322
PreRunE: func(cmd *cobra.Command, args []string) error {
2423
name, _ := cmd.Flags().GetString("name")
2524
if name == "" && len(args) == 0 {

cmd/delete.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import (
1414
)
1515

1616
var deleteCmd = &cobra.Command{
17-
Use: "delete [<app_id>]",
17+
Use: "delete",
1818
Short: "Delete an existing application",
19-
Args: cobra.RangeArgs(0, 1),
19+
Example: `speechly delete <app_id>
20+
speechly delete --app <app_id> --force`,
21+
Args: cobra.RangeArgs(0, 1),
2022
PreRunE: func(cmd *cobra.Command, args []string) error {
2123
appId, err := cmd.Flags().GetString("app")
2224
if err != nil {

cmd/deploy.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ func (u DeployWriter) Write(data []byte) (n int, err error) {
2727
}
2828

2929
var deployCmd = &cobra.Command{
30-
Use: "deploy [<app_id>] <directory>",
31-
Example: `speechly deploy <app_id> /path/to/config
32-
speechly deploy -a <app_id> .`,
30+
Use: "deploy",
3331
Short: "Send the contents of a local directory to training",
34-
Long: `The contents of the directory given as argument is sent to the
35-
API and validated. Then, a new model is trained and automatically deployed
36-
as the active model for the application.`,
32+
Long: "The contents of the directory given as argument is sent to the API and validated. Then, a new model is trained and automatically deployed as the active model for the application.",
33+
Example: `speechly deploy <app_id> /path/to/config
34+
speechly deploy --app <app_id> .
35+
speechly deploy --watch --app <app_id> .`,
3736
Args: cobra.RangeArgs(1, 2),
3837
PreRunE: func(cmd *cobra.Command, args []string) error {
3938
appId, _ := cmd.Flags().GetString("app")

cmd/describe.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import (
1010
)
1111

1212
var describeCmd = &cobra.Command{
13-
Use: "describe [<app_id>]",
14-
Short: "Print details about an application",
13+
Use: "describe",
14+
Short: "Print details about an application",
15+
Example: `speechly describe <app_id>
16+
speechly describe --app <app_id>`,
1517
Args: cobra.RangeArgs(0, 1),
1618
PreRunE: checkSoleAppArgument,
1719
Run: func(cmd *cobra.Command, args []string) {
@@ -34,16 +36,16 @@ var describeCmd = &cobra.Command{
3436
if app.App.DeployedAtTime != nil {
3537
deployedAt = app.App.DeployedAtTime.AsTime().String()
3638
}
37-
cmd.Printf("AppId:\t%s\n", app.App.Id)
38-
cmd.Printf("Name:\t%s\n", app.App.Name)
39-
cmd.Printf("Lang:\t%s\n", app.App.Language)
39+
cmd.Printf("App ID: %s\n", app.App.Id)
40+
cmd.Printf("Name: %s\n", app.App.Name)
41+
cmd.Printf("Language: %s\n", app.App.Language)
4042

4143
waitFor := configv1.App_STATUS_UNSPECIFIED
4244
if wait {
4345
waitFor = configv1.App_STATUS_TRAINED
4446
}
4547
waitForAppStatus(cmd, configClient, appId, waitFor)
46-
cmd.Printf("Deployed At:\t%s\n", deployedAt)
48+
cmd.Printf("Deployed at: %s\n", deployedAt)
4749
},
4850
}
4951

cmd/download.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ import (
1919
)
2020

2121
var downloadCmd = &cobra.Command{
22-
Use: "download [<app_id>] <directory> [flags]",
22+
Use: "download",
23+
Short: "Download the active configuration or model bundle of the given app",
24+
Long: "Fetches the currently stored configuration or model bundle. This command does not check for validity of the stored configuration, but downloads the latest version.",
2325
Example: `speechly download <app_id> /path/to/config
24-
speechly download -a <app_id> .
25-
speechly download -a <app_id> . --model tflite`,
26-
Short: "Download the active configuration or model bundle of the given app.",
27-
Long: `Fetches the currently stored configuration or model bundle. This command does not check for validity of the stored configuration, but downloads the latest version.`,
28-
Args: cobra.RangeArgs(1, 2),
26+
speechly download --app <app_id> . --model tflite`,
27+
Args: cobra.RangeArgs(1, 2),
2928
PreRunE: func(cmd *cobra.Command, args []string) error {
3029
appId, _ := cmd.Flags().GetString("app")
3130
if appId == "" {

cmd/edit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
var editCmd = &cobra.Command{
1313
Use: "edit",
1414
Short: "Edit an existing application",
15+
Example: `speechly edit --app <app_id> --name <new_name>`,
1516
Run: func(cmd *cobra.Command, args []string) {
1617
name, _ := cmd.Flags().GetString("name")
1718

0 commit comments

Comments
 (0)