Skip to content

Commit 09495ba

Browse files
committed
chore: lint fixes
1 parent c547847 commit 09495ba

File tree

2 files changed

+51
-56
lines changed

2 files changed

+51
-56
lines changed

helper/command/command.go

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@ type Command struct {
2222
Params []string
2323
Env []string
2424
WorkDir string
25-
StdoutFunc ReaderFunc
26-
SterrFunc ReaderFunc
25+
stdoutFunc ReaderFunc
26+
stderrFunc ReaderFunc
2727
}
2828

29-
func NewPanicOption() Option {
30-
return Option{
31-
PanicOnError: true,
32-
}
33-
}
3429
func NewAllowedCodesOption(codes ...int) Option {
3530
return Option{
3631
AllowedCodes: codes,
@@ -49,50 +44,50 @@ func NewCommand(command string, params ...string) *Command {
4944
return cmd
5045
}
5146

52-
func (C *Command) AddParam(param string) *Command {
53-
C.Params = append(C.Params, param)
54-
return C
47+
func (c *Command) AddParam(param string) *Command {
48+
c.Params = append(c.Params, param)
49+
return c
5550
}
5651

57-
func (C *Command) SetWorkDir(workDir string) *Command {
58-
C.WorkDir = workDir
59-
return C
52+
func (c *Command) SetWorkDir(workDir string) *Command {
53+
c.WorkDir = workDir
54+
return c
6055
}
61-
func (C *Command) SetEnv(env []string) *Command {
62-
C.Env = env
63-
return C
56+
func (c *Command) SetEnv(env []string) *Command {
57+
c.Env = env
58+
return c
6459
}
6560

66-
func (C *Command) AddEnv(env string) *Command {
67-
C.Env = append(C.Env, env)
68-
return C
61+
func (c *Command) AddEnv(env string) *Command {
62+
c.Env = append(c.Env, env)
63+
return c
6964
}
7065

71-
func (C *Command) SetStdoutFunc(StdoutFunc ReaderFunc) *Command {
72-
C.StdoutFunc = StdoutFunc
73-
return C
66+
func (c *Command) SetStdoutFunc(StdoutFunc ReaderFunc) *Command {
67+
c.stdoutFunc = StdoutFunc
68+
return c
7469
}
7570

76-
func (C *Command) SetStderrFunc(StderrtFunc ReaderFunc) *Command {
77-
C.SterrFunc = StderrtFunc
78-
return C
71+
func (c *Command) SetStderrFunc(StderrtFunc ReaderFunc) *Command {
72+
c.stderrFunc = StderrtFunc
73+
return c
7974
}
80-
func (C *Command) Run(opt ...Option) (exitCode int, err error) {
81-
return C.RunWithContext(context.Background(), opt...)
75+
func (c *Command) Run(opt ...Option) (exitCode int, err error) {
76+
return c.RunWithContext(context.Background(), opt...)
8277
}
8378

84-
func (C *Command) RunWithContext(ctx context.Context, opt ...Option) (exitCode int, err error) {
79+
func (c *Command) RunWithContext(ctx context.Context, opt ...Option) (exitCode int, err error) {
8580
wg := &sync.WaitGroup{}
8681
defer wg.Wait()
8782
var cmd *exec.Cmd
8883
if runtime.GOOS == "windows" {
89-
cmd = exec.CommandContext(ctx, C.Command, C.Params...)
84+
cmd = exec.CommandContext(ctx, c.Command, c.Params...)
9085
} else {
91-
fullCommand := append([]string{C.Command}, C.Params...)
86+
fullCommand := append([]string{c.Command}, c.Params...)
9287
cmd = exec.CommandContext(ctx, "nice", append([]string{"-20"}, fullCommand...)...)
9388
}
94-
cmd.Env = C.Env
95-
cmd.Dir = C.WorkDir
89+
cmd.Env = c.Env
90+
cmd.Dir = c.WorkDir
9691
stdout, err := cmd.StdoutPipe()
9792
if err != nil {
9893
return
@@ -106,8 +101,8 @@ func (C *Command) RunWithContext(ctx context.Context, opt ...Option) (exitCode i
106101
}
107102

108103
wg.Add(2)
109-
go C.readerStreamProcessor(ctx, wg, stdout, C.StdoutFunc)
110-
go C.readerStreamProcessor(ctx, wg, stderr, C.SterrFunc)
104+
go c.readerStreamProcessor(ctx, wg, stdout, c.stdoutFunc)
105+
go c.readerStreamProcessor(ctx, wg, stderr, c.stderrFunc)
111106

112107
err = cmd.Wait()
113108
if err != nil {
@@ -147,7 +142,7 @@ func allowedCodes(opts []Option, exitCode int) bool {
147142
return exitCode == 0
148143
}
149144

150-
func (C *Command) readerStreamProcessor(ctx context.Context, wg *sync.WaitGroup, reader io.ReadCloser, callbackFunc ReaderFunc) {
145+
func (c *Command) readerStreamProcessor(ctx context.Context, wg *sync.WaitGroup, reader io.ReadCloser, callbackFunc ReaderFunc) {
151146
defer wg.Done()
152147
buffer := make([]byte, 4096)
153148
loop:
@@ -172,8 +167,8 @@ loop:
172167
}
173168
}
174169

175-
func (C *Command) GetFullCommand() string {
176-
return fmt.Sprintf("%s %s", C.Command, strings.Join(C.Params, " "))
170+
func (c *Command) GetFullCommand() string {
171+
return fmt.Sprintf("%s %s", c.Command, strings.Join(c.Params, " "))
177172
}
178173

179174
func GetWD() string {
@@ -205,7 +200,7 @@ func StringToSlice(command string) (output []string) {
205200
} else if c == '\'' {
206201
cutQuote = !cutQuote
207202
}
208-
inLineWord = inLineWord + string(c)
203+
inLineWord += string(c)
209204
}
210205
output = append(output, inLineWord)
211206
return output

update/update.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ func NewUpdater(currentVersionString string, assetName string, noUpdates bool, t
7070
return updater, nil
7171
}
7272

73-
func (U *Updater) Run(wg *sync.WaitGroup, ctx context.Context) {
73+
func (u *Updater) Run(wg *sync.WaitGroup, ctx context.Context) {
7474
wg.Add(1)
7575
go func() {
7676
for {
77-
latestVersion, newUpdate, err := U.CheckForUpdate()
77+
latestVersion, newUpdate, err := u.CheckForUpdate()
7878
if err != nil {
7979
log.Error(err)
8080
select {
@@ -85,20 +85,20 @@ func (U *Updater) Run(wg *sync.WaitGroup, ctx context.Context) {
8585
}
8686
}
8787
if newUpdate {
88-
if err = U.update(latestVersion); err != nil {
88+
if err = u.update(latestVersion); err != nil {
8989
log.Error(err)
9090
continue
9191
}
9292
}
93-
U.runApplication(ctx)
93+
u.runApplication(ctx)
9494
}
9595
}()
9696
}
9797

98-
func (U *Updater) runApplication(ctx context.Context) {
98+
func (u *Updater) runApplication(ctx context.Context) {
9999
arguments := os.Args[1:]
100100
arguments = append(arguments, "--noUpdateMode")
101-
ecode, err := command.NewCommand(U.binaryPath, arguments...).
101+
ecode, err := command.NewCommand(u.binaryPath, arguments...).
102102
SetStderrFunc(func(buffer []byte, exit bool) {
103103
os.Stderr.Write(buffer)
104104
}).
@@ -113,27 +113,27 @@ func (U *Updater) runApplication(ctx context.Context) {
113113
}
114114
}
115115

116-
func (U *Updater) CheckForUpdate() (*GitHubRelease, bool, error) {
117-
if time.Since(U.lastCheckTime) <= *U.checkInterval {
118-
return U.lastRelease, false, nil
116+
func (u *Updater) CheckForUpdate() (*GitHubRelease, bool, error) {
117+
if time.Since(u.lastCheckTime) <= *u.checkInterval {
118+
return u.lastRelease, false, nil
119119
}
120120
latestRelease, err := GetGitHubLatestVersion()
121121
if err != nil {
122122
return nil, false, err
123123
}
124-
U.lastCheckTime = time.Now()
125-
U.lastRelease = latestRelease
124+
u.lastCheckTime = time.Now()
125+
u.lastRelease = latestRelease
126126

127127
latestReleaseVersion, err := semver.Parse(cleanVersion(latestRelease.TagName))
128128
if err != nil {
129129
return nil, false, err
130130
}
131131
l := log.WithFields(log.Fields{
132-
"currentVersion": U.currentVersion.String(),
132+
"currentVersion": u.currentVersion.String(),
133133
"latestVersion": latestReleaseVersion.String(),
134134
})
135-
if latestReleaseVersion.GT(U.currentVersion) {
136-
if U.noUpdates {
135+
if latestReleaseVersion.GT(u.currentVersion) {
136+
if u.noUpdates {
137137
l.Warn("Newer version available but updates are disabled")
138138
return nil, false, nil
139139
}
@@ -145,18 +145,18 @@ func (U *Updater) CheckForUpdate() (*GitHubRelease, bool, error) {
145145
return nil, false, nil
146146
}
147147

148-
func (U *Updater) update(githubRelease *GitHubRelease) error {
148+
func (u *Updater) update(githubRelease *GitHubRelease) error {
149149
var assetToDownload *GitHubAsset
150150
for _, asset := range githubRelease.Assets {
151-
if asset.Name == U.assetName {
151+
if asset.Name == u.assetName {
152152
assetToDownload = &asset
153153
break
154154
}
155155
}
156156
if assetToDownload == nil {
157-
return fmt.Errorf("no asset found with name %s for release %s", U.assetName, githubRelease.TagName)
157+
return fmt.Errorf("no asset found with name %s for release %s", u.assetName, githubRelease.TagName)
158158
}
159-
tmpDownloadPath := filepath.Join(U.tmpPath, fmt.Sprintf("%s.new", U.assetName))
159+
tmpDownloadPath := filepath.Join(u.tmpPath, fmt.Sprintf("%s.new", u.assetName))
160160
latestReleaseFile, err := os.Create(tmpDownloadPath)
161161
if err != nil {
162162
return err

0 commit comments

Comments
 (0)