Skip to content

Commit cd8de0f

Browse files
authored
documentation for commands (#81)
* documentation for commands * upgraded Cobra version
1 parent 1ccdf51 commit cd8de0f

40 files changed

+1981
-21
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ _pkg-init:
6161
%:
6262
GOOS=$(basename $@) go build -o bin/smartling.$@
6363

64+
docs:
65+
go run ./main.go docs
66+
6467
tidy:
6568
go mod tidy
6669

@@ -90,3 +93,4 @@ test_integration:
9093
go test ./tests/cmd/files/delete/...
9194
go test ./tests/cmd/projects/...
9295
go test ./tests/cmd/init/...
96+

cmd/cmd_root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewRootCmd() *cobra.Command {
3030
rootCmd := &cobra.Command{
3131
Use: "smartling-cli",
3232
Short: "Manage translation files using Smartling CLI.",
33-
Version: "2.4.1",
33+
Version: "2.5",
3434
Long: `Manage translation files using Smartling CLI.
3535
Complete documentation is available at https://www.smartling.com`,
3636
PersistentPreRun: func(cmd *cobra.Command, _ []string) {

cmd/docs/cmd_docs.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package docs
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/Smartling/smartling-cli/services/helpers/rlog"
7+
8+
"github.com/spf13/cobra"
9+
"github.com/spf13/cobra/doc"
10+
)
11+
12+
// NewDocsCmd creates a new command to generate docs.
13+
func NewDocsCmd() *cobra.Command {
14+
docsCmd := &cobra.Command{
15+
Use: "docs",
16+
Short: "Generate markdown docs for CLI commands",
17+
Hidden: true,
18+
RunE: func(cmd *cobra.Command, args []string) error {
19+
err := doc.GenMarkdownTree(cmd.Root(), "./docs")
20+
if err != nil {
21+
return fmt.Errorf("failed to generate docs: %v", err)
22+
}
23+
rlog.Infof("markdown docs generated in ./docs/")
24+
return nil
25+
},
26+
}
27+
28+
return docsCmd
29+
}

cmd/files/cmd_files.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ func NewFilesCmd() *cobra.Command {
1818
Aliases: []string{"f"},
1919
Short: "Used to access various files sub-commands.",
2020
Long: `Used to access various files sub-commands.`,
21+
Example: `
22+
# Check file status across locales
23+
24+
smartling-cli files status
25+
26+
`,
2127
Run: func(cmd *cobra.Command, args []string) {
2228
if len(args) == 0 && cmd.Flags().NFlag() == 0 {
2329
if err := cmd.Help(); err != nil {

cmd/files/delete/cmd_delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewDeleteCmd(initializer files.SrvInitializer) *cobra.Command {
2121
2222
Removes files from project according to specified pattern.
2323
24-
<uri> ` + help.GlobPattern + `
24+
` + "`<uri>` " + help.GlobPattern + `
2525
2626
If special value of "-" is specified as <uri>, then program will expect
2727
to read files list from stdin:

cmd/files/list/cmd_list.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Following variables are available:
4242
> .LastUploaded — timestamp when file was last uploaded;
4343
> .HasInstructions — true/false if file has translation instructions;
4444
45-
<uri> ` + help.GlobPattern + `
45+
` + "`<uri>` " + help.GlobPattern + `
4646
4747
4848
Available options:
@@ -55,6 +55,11 @@ Available options:
5555
--format <format>
5656
Override default listing format.
5757
` + help.AuthenticationOptions,
58+
Example: `
59+
# List project files
60+
61+
smartling-cli files list
62+
`,
5863
Run: func(_ *cobra.Command, args []string) {
5964
var uri string
6065
if len(args) > 0 {

cmd/files/pull/cmd_pull.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ to read files list from stdin:
4040
4141
cat files.txt | smartling-cli files pull -
4242
43-
<uri> ` + help.GlobPattern + `
43+
` + "`<uri>` " + help.GlobPattern + `
4444
4545
If --locale flag is not specified, all available locales are downloaded. To
4646
see available locales, use "status" command.
@@ -85,6 +85,11 @@ Available options:
8585
characters transformed;
8686
> contextMatchingInstrumented — to use with Chrome Context Capture;
8787
` + help.AuthenticationOptions,
88+
Example: `
89+
# Download translated files
90+
91+
smartling-cli files pull "**/*.json" --locale fr-FR --locale de-DE
92+
`,
8893
Run: func(_ *cobra.Command, args []string) {
8994
if len(args) > 0 {
9095
uri = args[0]

cmd/files/push/cmd_push.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,39 @@ File type will be deduced from file extension. If file extension is unknown,
5555
type should be specified manually by using --type option. That option also
5656
can be used to override detected file type.
5757
58-
<file> ` + help.GlobPattern + `
58+
` + "`<file>` " + help.GlobPattern + `
5959
6060
` + help.AuthenticationOptions,
61+
Example: `
62+
# Upload files to a translation job
63+
64+
smartling-cli files push my-file.txt --job "Website Update" --authorize
65+
66+
# Upload multiple files with pattern matching
67+
68+
smartling-cli files push "src/**/*.json" --job "App Localization"
69+
70+
# Manual branch naming
71+
72+
smartling-cli files push "**/*.txt" --branch "feature-branch"
73+
74+
# Automatic Git branch detection
75+
76+
smartling-cli files push "**/*.txt" --branch "@auto"
77+
78+
# All JSON files in subdirectories
79+
80+
smartling-cli files push "**/*.json"
81+
82+
# Specific file types
83+
84+
smartling-cli files push "**/*.{json,xml,properties}"
85+
86+
# Files matching naming convention
87+
88+
smartling-cli files push "**/messages_*.properties"
89+
90+
`,
6191
RunE: func(cmd *cobra.Command, args []string) error {
6292
ctx := cmd.Context()
6393
var (

cmd/files/status/cmd_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Following variables are available:
5050
> .FileURI — full file URI in Smartling system;
5151
> .Locale — locale ID for translated file and empty for source file;
5252
53-
<uri> ` + help.GlobPattern + `
53+
` + "`<uri>` " + help.GlobPattern + `
5454
5555
5656
Available options:

cmd/init/cmd_init.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ config values prior dialog:
3636
smartling-cli init --user=your_user_id
3737
3838
Also, --dry-run option can be used to just look at resulting config without
39-
overwritting anything:
39+
overwriting anything:
4040
4141
smartling-cli init --dry-run
4242
@@ -57,6 +57,18 @@ Default config values can be passed via following options:` +
5757
help.AuthenticationOptions + `
5858
-p --project <project>
5959
Specify default project.`,
60+
Example: `
61+
# Create a configuration file with your Smartling API credentials:
62+
# This creates a smartling.yml file in your current directory with your project settings.
63+
# Note: Running init again will overwrite the existing configuration file.
64+
65+
smartling-cli init
66+
67+
# Dry run of init command without overwriting the existing configuration file.
68+
69+
smartling-cli init --dry-run
70+
71+
`,
6072
Run: func(_ *cobra.Command, _ []string) {
6173
s, err := srvInitializer.InitSrv()
6274
if err != nil {

0 commit comments

Comments
 (0)