Skip to content

Commit 5f54abe

Browse files
feat: linting (#105)
* feat: linting Signed-off-by: jmeridth <jmeridth@gmail.com> Co-authored-by: Eddie Knight <knight@linux.com> * fix: handle some errors, because we should thanks copilot Signed-off-by: jmeridth <jmeridth@gmail.com> Co-authored-by: Eddie Knight <knight@linux.com> --------- Signed-off-by: jmeridth <jmeridth@gmail.com> Co-authored-by: Eddie Knight <knight@linux.com>
1 parent f2f569c commit 5f54abe

File tree

5 files changed

+58
-17
lines changed

5 files changed

+58
-17
lines changed

.github/workflows/lint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pull-requests: read
12+
13+
jobs:
14+
lint:
15+
name: lint
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4.2.2
19+
- uses: actions/setup-go@v5.4.0
20+
with:
21+
go-version: stable
22+
- name: golangci-lint
23+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd
24+
with:
25+
version: v2.0.2

cmd/generate-plugin.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func init() {
3939
genPluginCmd.PersistentFlags().StringP("service-name", "n", "", "The name of the service (e.g. 'ECS, AKS, GCS').")
4040
genPluginCmd.PersistentFlags().StringP("output-dir", "o", "generated-plugin/", "Pathname for the generated plugin.")
4141

42-
viper.BindPFlag("source-path", genPluginCmd.PersistentFlags().Lookup("source-path"))
43-
viper.BindPFlag("local-templates", genPluginCmd.PersistentFlags().Lookup("local-templates"))
44-
viper.BindPFlag("service-name", genPluginCmd.PersistentFlags().Lookup("service-name"))
45-
viper.BindPFlag("output-dir", genPluginCmd.PersistentFlags().Lookup("output-dir"))
42+
_ = viper.BindPFlag("source-path", genPluginCmd.PersistentFlags().Lookup("source-path"))
43+
_ = viper.BindPFlag("local-templates", genPluginCmd.PersistentFlags().Lookup("local-templates"))
44+
_ = viper.BindPFlag("service-name", genPluginCmd.PersistentFlags().Lookup("service-name"))
45+
_ = viper.BindPFlag("output-dir", genPluginCmd.PersistentFlags().Lookup("output-dir"))
4646

4747
rootCmd.AddCommand(genPluginCmd)
4848
}
@@ -95,7 +95,10 @@ func setupTemplatingEnvironment() error {
9595
TemplatesDir = viper.GetString("local-templates")
9696
} else {
9797
TemplatesDir = filepath.Join(os.TempDir(), "privateer-templates")
98-
setupTemplatesDir()
98+
err := setupTemplatesDir()
99+
if err != nil {
100+
return fmt.Errorf("error setting up templates directory: %w", err)
101+
}
99102
}
100103

101104
OutputDir = viper.GetString("output-dir")
@@ -159,7 +162,12 @@ func generateFileFromTemplate(data CatalogData, templatePath, OutputDir string)
159162
return fmt.Errorf("error creating output file %s: %w", outputPath, err)
160163
}
161164

162-
defer outputFile.Close()
165+
defer func() {
166+
err := outputFile.Close()
167+
if err != nil {
168+
logger.Error("error closing output file %s: %w", outputPath, err)
169+
}
170+
}()
163171

164172
err = tmpl.Execute(outputFile, data)
165173
if err != nil {

cmd/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ var installCmd = &cobra.Command{
2121

2222
func init() {
2323
installCmd.PersistentFlags().BoolP("store", "s", false, "Github repo to source the plugin from.")
24-
viper.BindPFlag("store", installCmd.PersistentFlags().Lookup("store"))
24+
_ = viper.BindPFlag("store", installCmd.PersistentFlags().Lookup("store"))
2525
}

cmd/list.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"log"
56
"path"
67
"strings"
78

@@ -20,28 +21,31 @@ var listCmd = &cobra.Command{
2021
Short: "Consult the Charts! List all plugins that have been installed.",
2122
Run: func(cmd *cobra.Command, args []string) {
2223
if viper.GetBool("all") {
23-
fmt.Fprintln(writer, "| Plugin \t | Available \t| Requested \t|")
24+
_, _ = fmt.Fprintln(writer, "| Plugin \t | Available \t| Requested \t|")
2425
for _, pluginPkg := range GetPlugins() {
25-
fmt.Fprintf(writer, "| %s \t | %t \t| %t \t|\n", pluginPkg.Name, pluginPkg.Available, pluginPkg.Requested)
26+
_, _ = fmt.Fprintf(writer, "| %s \t | %t \t| %t \t|\n", pluginPkg.Name, pluginPkg.Available, pluginPkg.Requested)
2627
}
2728
} else {
2829
// list only the available plugins
29-
fmt.Fprintln(writer, "| Plugin \t | Requested \t|")
30+
_, _ = fmt.Fprintln(writer, "| Plugin \t | Requested \t|")
3031
for _, pluginPkg := range GetPlugins() {
3132
if pluginPkg.Available {
32-
fmt.Fprintf(writer, "| %s \t | %t \t|\n", pluginPkg.Name, pluginPkg.Requested)
33+
_, _ = fmt.Fprintf(writer, "| %s \t | %t \t|\n", pluginPkg.Name, pluginPkg.Requested)
3334
}
3435
}
3536
}
36-
writer.Flush()
37+
err := writer.Flush()
38+
if err != nil {
39+
log.Printf("Error flushing writer: %v", err)
40+
}
3741
},
3842
}
3943

4044
func init() {
4145
rootCmd.AddCommand(listCmd)
4246

4347
listCmd.PersistentFlags().BoolP("all", "a", false, "Review the Fleet! List all plugins that have been installed or requested in the current config.")
44-
viper.BindPFlag("all", listCmd.PersistentFlags().Lookup("all"))
48+
_ = viper.BindPFlag("all", listCmd.PersistentFlags().Lookup("all"))
4549
}
4650

4751
// GetRequestedPlugins returns a list of plugin names requested in the config

cmd/version.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"log"
56

67
"github.com/spf13/cobra"
78
"github.com/spf13/viper"
@@ -14,10 +15,13 @@ var versionCmd = &cobra.Command{
1415
Long: ``, // TODO
1516
Run: func(cmd *cobra.Command, args []string) {
1617
if viper.GetBool("verbose") {
17-
fmt.Fprintln(writer, fmt.Sprintf("Version:\t%s", buildVersion))
18-
fmt.Fprintln(writer, fmt.Sprintf("Commit:\t%s", buildGitCommitHash))
19-
fmt.Fprintln(writer, fmt.Sprintf("Build Time:\t%s", buildTime))
20-
writer.Flush()
18+
_, _ = fmt.Fprintf(writer, "Version:\t%s\n", buildVersion)
19+
_, _ = fmt.Fprintf(writer, "Commit:\t%s\n", buildGitCommitHash)
20+
_, _ = fmt.Fprintf(writer, "Build Time:\t%s\n", buildTime)
21+
err := writer.Flush()
22+
if err != nil {
23+
log.Printf("Error flushing writer: %v", err)
24+
}
2125
} else {
2226
fmt.Println(buildVersion)
2327
}

0 commit comments

Comments
 (0)