Skip to content

Commit c823aac

Browse files
committed
📝 Add examples to commands reference
1 parent eb2a3a1 commit c823aac

Some content is hidden

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

43 files changed

+329
-91
lines changed

cmd/alias.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ var aliasCmd = &cobra.Command{
1212
They help you use another name for a table so that you don't have to write profileName_pluginName_tableName every time.`,
1313
Aliases: []string{"aliases"},
1414
RunE: controller.AliasList,
15+
Example: `# List the aliases
16+
anyquery alias
17+
18+
# Add an alias
19+
anyquery alias add myalias mytable
20+
21+
# Delete an alias
22+
anyquery alias delete myalias`,
1523
}
1624

1725
var aliasAddCmd = &cobra.Command{
@@ -20,7 +28,8 @@ var aliasAddCmd = &cobra.Command{
2028
Short: "Add an alias",
2129
Long: `Add an alias.
2230
The alias name must be unique and not already used by a table.`,
23-
RunE: controller.AliasAdd,
31+
RunE: controller.AliasAdd,
32+
Example: `anyquery alias add myalias mytable`,
2433
}
2534

2635
var aliasDeleteCmd = &cobra.Command{
@@ -29,6 +38,7 @@ var aliasDeleteCmd = &cobra.Command{
2938
Aliases: []string{"rm", "remove"},
3039
Args: cobra.MaximumNArgs(1),
3140
RunE: controller.AliasDelete,
41+
Example: `anyquery alias delete myalias`,
3242
}
3343

3444
var aliasListCmd = &cobra.Command{

cmd/plugins.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var pluginInstallCmd = &cobra.Command{
2222
Args: cobra.MaximumNArgs(2),
2323
SuggestFor: []string{"get"},
2424
RunE: controller.PluginInstall,
25+
Example: `anyquery plugin install github`,
2526
}
2627

2728
var pluginUninstallCmd = &cobra.Command{
@@ -32,13 +33,15 @@ var pluginUninstallCmd = &cobra.Command{
3233
Aliases: []string{"rm", "remove", "delete"},
3334
Args: cobra.MinimumNArgs(1),
3435
RunE: controller.PluginUninstall,
36+
Example: `anyquery plugin uninstall github`,
3537
}
3638

3739
var pluginUpdateCmd = &cobra.Command{
38-
Use: "update [...plugin]",
39-
Short: "Update n or all plugins",
40-
Long: "Update plugins\nIf no plugin is specified, all plugins will be updated",
41-
RunE: controller.PluginUpdate,
40+
Use: "update [...plugin]",
41+
Short: "Update n or all plugins",
42+
Long: "Update plugins\nIf no plugin is specified, all plugins will be updated",
43+
RunE: controller.PluginUpdate,
44+
Example: `anyquery registry refresh && anyquery plugin update github`,
4245
}
4346

4447
func init() {

cmd/profiles.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var profilesCmd = &cobra.Command{
1212
Alias to profile list.`,
1313
Aliases: []string{"profile"},
1414
RunE: controller.ProfileList,
15+
Example: `# List the profiles
16+
anyquery profiles`,
1517
}
1618

1719
var profilesUpdateCmd = &cobra.Command{
@@ -22,7 +24,8 @@ var profilesUpdateCmd = &cobra.Command{
2224
If only two arguments are provided, we consider that the registry is the default one.
2325
If no argument is provided, the command will prompt you the registry, the plugin and the profile to update.
2426
Note: This command requires the tty to be interactive.`,
25-
RunE: controller.ProfileUpdate,
27+
RunE: controller.ProfileUpdate,
28+
Example: `anyquery profiles update default github myprofile`,
2629
}
2730

2831
var profilesNewCmd = &cobra.Command{
@@ -35,6 +38,7 @@ If no argument is provided, the command will prompt you the registry, the plugin
3538
Note: This command requires the tty to be interactive.`,
3639
RunE: controller.ProfileNew,
3740
Aliases: []string{"create", "add"},
41+
Example: `anyquery profiles new default github default`,
3842
}
3943

4044
var profilesListCmd = &cobra.Command{
@@ -47,6 +51,7 @@ If only one argument is provided, the results will be filtered by the registry.
4751
If two arguments are provided, the results will be filtered by the registry and the plugin.`,
4852
Aliases: []string{"ls"},
4953
RunE: controller.ProfileList,
54+
Example: `anyquery profiles list`,
5055
}
5156

5257
var profilesDeleteCmd = &cobra.Command{
@@ -58,6 +63,7 @@ If only two arguments are provided, we consider that the registry is the default
5863
If no argument is provided, the command will prompt you the registry, the plugin and the profile to create.`,
5964
Aliases: []string{"rm", "remove"},
6065
RunE: controller.ProfileDelete,
66+
Example: `anyquery profiles delete default github default`,
6167
}
6268

6369
func init() {

cmd/query.go

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ The query can be specified as an argument or read from stdin.
1313
If no query is provided, the command will launch an interactive input.`,
1414
RunE: controller.Query,
1515
Aliases: []string{"q", "run"},
16+
Example: `# Run a one-off query
17+
anyquery query -d mydatabase.db -q "SELECT * FROM mytable"
18+
19+
# Open the interactive shell
20+
anyquery query -d mydatabase.db
21+
22+
# Open the interactive shell in memory
23+
anyquery query
24+
25+
# Query from stdin
26+
echo "SELECT * FROM mytable" | anyquery query -d mydatabase.db`,
1627
}
1728

1829
func init() {

cmd/registry.go

+6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ var registryCmd = &cobra.Command{
1212
Aliases: []string{"registries"},
1313
SuggestFor: []string{"store"},
1414
Args: cobra.NoArgs,
15+
Example: "anyquery registry list",
1516
}
1617

1718
var registryListCmd = &cobra.Command{
1819
Use: "list",
1920
Short: "List the registries where plugins can be downloaded",
2021
RunE: controller.RegistryList,
2122
Aliases: []string{"ls"},
23+
Example: "anyquery registry list",
2224
}
2325

2426
var registryAddCmd = &cobra.Command{
@@ -27,13 +29,15 @@ var registryAddCmd = &cobra.Command{
2729
Args: cobra.MaximumNArgs(2),
2830
RunE: controller.RegistryAdd,
2931
Aliases: []string{"new", "create", "register", "install"},
32+
Example: "anyquery registry add internal_reg https://registry.anyquery.dev/v0/registry/",
3033
}
3134

3235
var registryRemoveCmd = &cobra.Command{
3336
Use: "remove",
3437
Short: "Remove a registry",
3538
RunE: controller.RegistryRemove,
3639
Aliases: []string{"rm", "delete"},
40+
Example: "anyquery registry remove internal_reg",
3741
}
3842

3943
var registryGetCmd = &cobra.Command{
@@ -42,6 +46,7 @@ var registryGetCmd = &cobra.Command{
4246
Args: cobra.ExactArgs(1),
4347
RunE: controller.RegistryGet,
4448
Aliases: []string{"info", "show", "inspect"},
49+
Example: "anyquery registry get internal_reg",
4550
}
4651

4752
var registryRefreshCmd = &cobra.Command{
@@ -52,6 +57,7 @@ If a name is provided, only this registry will be refreshed. Otherwise, all regi
5257
Args: cobra.MaximumNArgs(1),
5358
RunE: controller.RegistryRefresh,
5459
Aliases: []string{"update", "sync", "fetch", "pull"},
60+
Example: "anyquery registry refresh",
5561
}
5662

5763
func init() {

cmd/root.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ by writing SQL queries. It can be extended with plugins`,
1717
// Thanks https://github.com/spf13/cobra/issues/340#issuecomment-243790200
1818
SilenceUsage: true,
1919
RunE: controller.Query,
20-
Example: `-- Run a one-off query
20+
Example: `# Run a one-off query
2121
anyquery -d mydatabase.db -q "SELECT * FROM mytable"
2222
23-
-- Open the interactive shell
23+
# Open the interactive shell
2424
anyquery -d mydatabase.db
2525
26-
-- Open a database in memory
26+
# Open a database in memory
2727
anyquery -d ":memory:"
2828
`,
2929
}

cmd/server.go

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ var serverCmd = &cobra.Command{
1111
Long: `Listens for incoming connections and allows you to run queries
1212
using any MySQL client.`,
1313
RunE: controller.Server,
14+
Example: `# Start the server by opening anyquery.db by default
15+
anyquery server
16+
17+
# Start the server on a specific host and port
18+
anyquery server --host 127.0.0.1 --port 3306
19+
20+
# Start the server with a specific database
21+
anyquery server -d mydatabase.db
22+
23+
# Increase the log level and redirect the output to a file
24+
anyquery server --log-level debug --log-file /var/log/anyquery.log`,
1425
}
1526

1627
func init() {

cmd/tool.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The password is hashed using the mysql_native_password algorithm
2727
which can be summarized as HEX(SHA1(SHA1(password)))`,
2828
Aliases: []string{"hash-password", "mysql-native-password"},
2929
RunE: controller.MySQLPassword,
30+
Example: `echo "password" | anyquery tool mysql-password`,
3031
}
3132

3233
var toolDevCmd = &cobra.Command{
@@ -42,6 +43,8 @@ var toolDevInitCmd = &cobra.Command{
4243
The module URL is the go mod URL of the plugin.`,
4344
Args: cobra.RangeArgs(1, 2),
4445
RunE: controller.DevInit,
46+
Example: `# Initialize a new plugin in a new directory,
47+
anyquery tool dev init github.com/julien040/anyquery/plugins/voynich-manuscript voynich-manuscript`,
4548
}
4649

4750
var toolDevNewTableCmd = &cobra.Command{
@@ -52,18 +55,21 @@ var toolDevNewTableCmd = &cobra.Command{
5255
The table name must only contain alphanumeric characters and underscores. Other characters will be replaced by underscores.`,
5356
Args: cobra.ExactArgs(1),
5457
RunE: controller.DevNewTable,
58+
Example: `# Inside the plugin directory, create a new table file
59+
anyquery tool dev new-table my_table`,
5560
}
5661

5762
var toolGenerateDocCmd = &cobra.Command{
5863
Use: "generate-doc [dir]",
5964
Short: "Generate the markdown documentation of the CLI",
60-
Args: cobra.ExactArgs(1),
65+
Args: cobra.ExactArgs(1),
6166
RunE: func(cmd *cobra.Command, args []string) error {
6267
return doc.GenMarkdownTree(rootCmd, args[0])
6368
},
69+
Example: `# Generate the doc in the docs directory
70+
anyquery tool generate-doc docs`,
6471
}
6572

66-
6773
func init() {
6874
rootCmd.AddCommand(toolCmd)
6975
toolCmd.AddCommand(toolHashDirCmd)

website/src/content/docs/docs/reference/Commands/anyquery.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@ A tool to query any data source
1010
Anyquery allows you to query any data source
1111
by writing SQL queries. It can be extended with plugins
1212

13-
```
13+
```bash
1414
anyquery [database] [query] [flags]
1515
```
1616

17-
### Options
17+
### Examples
18+
19+
```bash
20+
# Run a one-off query
21+
anyquery -d mydatabase.db -q "SELECT * FROM mytable"
22+
23+
# Open the interactive shell
24+
anyquery -d mydatabase.db
25+
26+
# Open a database in memory
27+
anyquery -d ":memory:"
1828

1929
```
30+
31+
### Options
32+
33+
```bash
2034
-c, --config string Path to the configuration database
2135
--csv Output format as CSV
2236
-d, --database string Database to connect to (a path or :memory:)
@@ -38,7 +52,6 @@ anyquery [database] [query] [flags]
3852
-q, --query string Query to run
3953
--read-only Start the server in read-only mode
4054
--readonly Start the server in read-only mode
41-
-v, --version Print the version of the program
4255
```
4356

4457
### SEE ALSO

website/src/content/docs/docs/reference/Commands/anyquery_alias.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,26 @@ Manage the aliases
1010
Manage the aliases.
1111
They help you use another name for a table so that you don't have to write profileName_pluginName_tableName every time.
1212

13-
```
13+
```bash
1414
anyquery alias [flags]
1515
```
1616

17-
### Options
17+
### Examples
18+
19+
```bash
20+
# List the aliases
21+
anyquery alias
22+
23+
# Add an alias
24+
anyquery alias add myalias mytable
1825

26+
# Delete an alias
27+
anyquery alias delete myalias
1928
```
29+
30+
### Options
31+
32+
```bash
2033
-c, --config string Path to the configuration database
2134
--csv Output format as CSV
2235
--format string Output format (pretty, json, csv, plain)

website/src/content/docs/docs/reference/Commands/anyquery_alias_add.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@ Add an alias
1010
Add an alias.
1111
The alias name must be unique and not already used by a table.
1212

13-
```
13+
```bash
1414
anyquery alias add [alias] [table] [flags]
1515
```
1616

17-
### Options
17+
### Examples
1818

19+
```bash
20+
anyquery alias add myalias mytable
1921
```
22+
23+
### Options
24+
25+
```bash
2026
-h, --help help for add
2127
```
2228

2329
### Options inherited from parent commands
2430

25-
```
31+
```bash
2632
-c, --config string Path to the configuration database
2733
```
2834

website/src/content/docs/docs/reference/Commands/anyquery_alias_delete.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@ description: Learn how to use the anyquery alias delete command in AnyQuery.
55

66
Delete an alias
77

8-
```
8+
```bash
99
anyquery alias delete [alias] [flags]
1010
```
1111

12-
### Options
12+
### Examples
1313

14+
```bash
15+
anyquery alias delete myalias
1416
```
17+
18+
### Options
19+
20+
```bash
1521
-h, --help help for delete
1622
```
1723

1824
### Options inherited from parent commands
1925

20-
```
26+
```bash
2127
-c, --config string Path to the configuration database
2228
```
2329

website/src/content/docs/docs/reference/Commands/anyquery_alias_list.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ description: Learn how to use the anyquery alias list command in AnyQuery.
55

66
List the aliases
77

8-
```
8+
```bash
99
anyquery alias list [flags]
1010
```
1111

1212
### Options
1313

14-
```
14+
```bash
1515
--csv Output format as CSV
1616
--format string Output format (pretty, json, csv, plain)
1717
-h, --help help for list
@@ -21,7 +21,7 @@ anyquery alias list [flags]
2121

2222
### Options inherited from parent commands
2323

24-
```
24+
```bash
2525
-c, --config string Path to the configuration database
2626
```
2727

0 commit comments

Comments
 (0)