Skip to content

Commit 8bb1f1c

Browse files
feature: improve starting from zero UX
1 parent fbcf3b3 commit 8bb1f1c

File tree

6 files changed

+58
-11
lines changed

6 files changed

+58
-11
lines changed

.codacy/codacy.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

cli-v2.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import (
99
)
1010

1111
func main() {
12-
fmt.Println("Running original CLI functionality...")
13-
// Original functionality
14-
config.Init()
15-
1612
configErr := cfg.ReadConfigFile(config.Config.ProjectConfigFile())
1713
// whenever there is no configuration file, the only command allowed to run is the 'init'
1814
if configErr != nil && len(os.Args) > 1 && os.Args[1] != "init" {

cmd/init.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ var initCmd = &cobra.Command{
2929
Short: "Bootstraps project configuration",
3030
Long: "Bootstraps project configuration, creates codacy configuration file",
3131
Run: func(cmd *cobra.Command, args []string) {
32+
33+
config.Init()
34+
3235
if len(codacyRepositoryToken) == 0 {
3336
fmt.Println("No project token was specified, skipping fetch configurations ")
3437
noTools := []tools.Tool{}

cmd/root.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,31 @@ import (
44
"fmt"
55
"os"
66

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

1011
var rootCmd = &cobra.Command{
1112
Use: "codacy-cli",
12-
Short: "Codacy CLI",
13-
Long: "Code analysis",
13+
Short: "Codacy CLI - A command line interface for Codacy",
14+
Long: `Codacy CLI is a command line tool that helps you interact with Codacy.
15+
It provides functionality for code analysis, configuration management,
16+
and integration with Codacy's services.
17+
18+
To get started, try running one of these commands:
19+
codacy-cli init - Initialize a new project
20+
codacy-cli install - Install required tools
21+
codacy-cli analyze - Run code analysis`,
1422
Run: func(cmd *cobra.Command, args []string) {
23+
// Check if .codacy directory exists
24+
if _, err := os.Stat(".codacy"); os.IsNotExist(err) {
25+
// Show welcome message if .codacy doesn't exist
26+
showWelcomeMessage()
27+
return
28+
}
29+
30+
// If .codacy exists, show regular help
31+
cmd.Help()
1532
},
1633
}
1734

@@ -21,3 +38,24 @@ func Execute() {
2138
os.Exit(1)
2239
}
2340
}
41+
42+
func showWelcomeMessage() {
43+
bold := color.New(color.Bold)
44+
cyan := color.New(color.FgCyan)
45+
yellow := color.New(color.FgYellow)
46+
47+
fmt.Println()
48+
bold.Println("👋 Welcome to Codacy CLI!")
49+
fmt.Println()
50+
fmt.Println("This tool helps you analyze and maintain code quality in your projects.")
51+
fmt.Println()
52+
yellow.Println("To get started, you'll need a Codacy API token.")
53+
fmt.Println("You can find your API token in Codacy under:")
54+
fmt.Println("Account > Access Management > API Tokens")
55+
fmt.Println()
56+
cyan.Println("Initialize your project with:")
57+
fmt.Println(" codacy-cli init --repository-token YOUR_TOKEN")
58+
fmt.Println()
59+
fmt.Println("Or run without a token to use local configuration:")
60+
fmt.Println(" codacy-cli init")
61+
}

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ require github.com/spf13/cobra v1.8.0
66

77
require (
88
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/fatih/color v1.18.0 // indirect
10+
github.com/mattn/go-colorable v0.1.13 // indirect
11+
github.com/mattn/go-isatty v0.0.20 // indirect
912
github.com/pmezard/go-difflib v1.0.0 // indirect
13+
golang.org/x/sys v0.25.0 // indirect
1014
)
1115

1216
require (

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5Jflh
4141
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
4242
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
4343
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
44+
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
45+
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
4446
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
4547
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
4648
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@@ -95,6 +97,11 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
9597
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
9698
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
9799
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
100+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
101+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
102+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
103+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
104+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
98105
github.com/mholt/archiver/v4 v4.0.0-alpha.8 h1:tRGQuDVPh66WCOelqe6LIGh0gwmfwxUrSSDunscGsRM=
99106
github.com/mholt/archiver/v4 v4.0.0-alpha.8/go.mod h1:5f7FUYGXdJWUjESffJaYR4R60VhnHxb2X3T1teMyv5A=
100107
github.com/nwaples/rardecode/v2 v2.0.0-beta.2 h1:e3mzJFJs4k83GXBEiTaQ5HgSc/kOK8q0rDaRO0MPaOk=
@@ -194,6 +201,10 @@ golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7w
194201
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
195202
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
196203
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
204+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
205+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
206+
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
207+
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
197208
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
198209
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
199210
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

0 commit comments

Comments
 (0)