Skip to content

Commit 4d692e4

Browse files
authored
Merge pull request #63 from codacy/PLUTO-1376_docs
[PLUTO-1376] Improve readme/help command
2 parents dd841e6 + ab6b168 commit 4d692e4

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# codacy-cli-v2
22

3-
The `codacy-cli-v2` is a command-line tool for Codacy that supports analyzing code using tools like ESLint and uploading the results in SARIF format to Codacy. It provides two main commands: `analyze` and `upload`.
3+
The Codacy CLI (version 2) is a command-line tool that supports analyzing code using tools like ESLint and uploading the results in SARIF format to Codacy.
4+
The tool is invoked using the `codacy-cli` command, and provides two main commands: analyze and upload.
45

56
### Commands
67

@@ -32,13 +33,13 @@ The `codacy-cli-v2` is a command-line tool for Codacy that supports analyzing co
3233
tools:
3334
3435

35-
- **`codacy-cli-v2 install`**: Command to install the specified node and eslint versions before running analysis.
36+
- **`codacy-cli install`**: Command to install the specified node and eslint versions before running analysis.
3637

3738
## Download
3839

3940
### MacOS (brew)
4041

41-
To install `codacy-cli-v2` using Homebrew:
42+
To install `codacy-cli` using Homebrew:
4243

4344
```bash
4445
brew install codacy/codacy-cli-v2/codacy-cli-v2

cmd/root.go

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67

78
"github.com/fatih/color"
89
"github.com/spf13/cobra"
910
)
1011

1112
var rootCmd = &cobra.Command{
12-
Use: "codacy-cli",
13-
Short: "Codacy CLI - A command line interface for Codacy",
14-
Long: ``,
13+
Use: "codacy-cli",
14+
Short: "Codacy CLI - A command line interface for Codacy",
15+
Long: "",
16+
Example: getExampleText(),
1517
Run: func(cmd *cobra.Command, args []string) {
1618
// Check if .codacy directory exists
1719
if _, err := os.Stat(".codacy"); os.IsNotExist(err) {
@@ -52,4 +54,61 @@ func showWelcomeMessage() {
5254
fmt.Println()
5355
fmt.Println("Or run without a token to use local configuration:")
5456
fmt.Println(" codacy-cli init")
57+
fmt.Println()
58+
fmt.Println("For more information about available commands, run:")
59+
fmt.Println(" codacy-cli --help")
60+
}
61+
62+
func getExampleText() string {
63+
return color.New(color.FgCyan).Sprint("Initialize a project:") + "\n" +
64+
color.New(color.FgGreen).Sprint(" codacy-cli init") + "\n\n" +
65+
color.New(color.FgCyan).Sprint("Install required tools:") + "\n" +
66+
color.New(color.FgGreen).Sprint(" codacy-cli install") + "\n\n" +
67+
color.New(color.FgCyan).Sprint("Run analysis with ESLint:") + "\n" +
68+
color.New(color.FgGreen).Sprint(" codacy-cli analyze --tool eslint") + "\n\n" +
69+
color.New(color.FgCyan).Sprint("Run analysis and output in SARIF format:") + "\n" +
70+
color.New(color.FgGreen).Sprint(" codacy-cli analyze --tool eslint --format sarif") + "\n\n" +
71+
color.New(color.FgCyan).Sprint("Upload results to Codacy:") + "\n" +
72+
color.New(color.FgGreen).Sprint(" codacy-cli upload -s results.sarif -c <commit-uuid> -t <project-token>")
73+
}
74+
75+
func init() {
76+
// Add global flags here
77+
rootCmd.PersistentFlags().StringP("config", "c", filepath.Join(".codacy", "codacy.yaml"), "config file")
78+
79+
// Customize help template
80+
rootCmd.SetUsageTemplate(`
81+
` + color.New(color.FgCyan).Sprint("Usage:") + `
82+
{{.UseLine}}{{if .HasAvailableSubCommands}}
83+
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
84+
85+
` + color.New(color.FgCyan).Sprint("Aliases:") + `
86+
{{.NameAndAliases}}{{end}}{{if .HasExample}}
87+
88+
` + color.New(color.FgCyan).Sprint("Examples:") + `
89+
{{.Example}}{{end}}{{if .HasAvailableSubCommands}}
90+
91+
` + color.New(color.FgCyan).Sprint("Available Commands:") + `{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
92+
` + "{{$cmd := .Name}}" + color.New(color.FgGreen).Sprintf("{{rpad .Name .NamePadding}}") + ` {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
93+
94+
` + color.New(color.FgCyan).Sprint("Flags:") + `
95+
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}
96+
97+
` + color.New(color.FgCyan).Sprint("Global Flags:") + `
98+
{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}
99+
100+
` + color.New(color.FgCyan).Sprint("Additional help topics:") + `{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
101+
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}
102+
103+
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
104+
105+
` + color.New(color.FgCyan).Sprint("Configuration Example") + ` (.codacy/codacy.yaml):
106+
runtimes:
107+
108+
tools:
109+
110+
111+
` + color.New(color.FgCyan).Sprint("For more information and examples, visit:") + `
112+
https://github.com/codacy/codacy-cli-v2
113+
`)
55114
}

0 commit comments

Comments
 (0)