Skip to content

Commit

Permalink
chores: Make the suggestions requested
Browse files Browse the repository at this point in the history
  • Loading branch information
yannick2009 committed May 12, 2024
1 parent b575858 commit 0cb5ae6
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 181 deletions.
4 changes: 2 additions & 2 deletions cmd/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

var (
ErrBadUsageAliasCmd error = errors.New("bad usage of alias command")
ErrBadUsageAliasCmd = errors.New("bad usage of alias command")
)

// aliasCmd represents the alias command
Expand All @@ -19,7 +19,7 @@ var aliasCmd = &cobra.Command{
Short: "Sets the alias for a project, whose name might be too big",
Long: `The idea is instead of having to type a-very-long-project-name-every-time you can alias it to
avlpn or something smaller and use that to query pman`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
if len(args) != 2 {
fmt.Println("Usage: pman alias <a-long-project-name> <alias>")
return ErrBadUsageAliasCmd
Expand Down
4 changes: 2 additions & 2 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
)

var (
ErrBadUsageDelCmd error = errors.New("bad usage of delete command")
ErrBadUsageDelCmd = errors.New("bad usage of delete command")
)

var delCmd = &cobra.Command{
Use: "delete",
Short: "Deletes a project from the index database. This does not delete the project from the filesystem",
Aliases: []string{"del", "d"},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
if len(args) != 1 {
fmt.Println("Usage : pman delete <projectName>")
return ErrBadUsageDelCmd
Expand Down
4 changes: 2 additions & 2 deletions cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
)

var (
ErrBadUsageInfoCmd error = errors.New("bad usage of info command")
ErrBadUsageInfoCmd = errors.New("bad usage of info command")
)

var infoCmd = &cobra.Command{
Use: "info",
Short: "The info command pretty prints the README.md file present at the root of the specified project.",
Aliases: []string{"ifo", "ifno", "ino"},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
if len(args) != 1 {
fmt.Println("Please provide a project name")
return ErrBadUsageInfoCmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var initCmd = &cobra.Command{
Running pman init <dirname> is the same as running: pman add <dirname>/*
`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
return pkg.InitDirs(args)
},
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ var lsCmd = &cobra.Command{
`,
RunE: func(cmd *cobra.Command, args []string) error {
filterFlag, _ := cmd.Flags().GetString("f")
oldUi, _ := cmd.Flags().GetBool("o")
data, err := db.GetAllRecords(db.DBName, StatusBucket)
if err != nil {
return err
}
if filterFlag != "" {
fmt.Println("Filtering by status : ", filterFlag)
data := utils.FilterByStatus(data, filterFlag)
ui.RenderTable(data)
data = utils.FilterByStatus(data, filterFlag)
}
ui.RenderTable(data)
return nil
if oldUi {
return ui.RenderTable(data)
}
return ui.RenderInteractiveTable(data)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var resetCmd = &cobra.Command{
Use: "reset",
Short: "Deletes the current indexed projects, run pman init to reindex the projects",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
err := db.DeleteDb(db.DBName)
if err != nil {
fmt.Println(err)
Expand Down
20 changes: 12 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ import (
)

const (
StatusBucket string = "projects"
ProjectPathBucket string = "projectPaths"
ProjectAliasBucket string = "projectAliases"
version string = "1.0"
StatusBucket = "projects"
ProjectPathBucket = "projectPaths"
ProjectAliasBucket = "projectAliases"
version = "1.0"
)

var (
ErrNoArgs = errors.New("this command has no argument")
)

var rootCmd = &cobra.Command{
Use: "pman",
Short: "A cli project manager",
Version: version,
Use: "pman",
Short: "A cli project manager",
Version: version,
SilenceUsage: true,
RunE: func(_ *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("this command has no argument")
return ErrNoArgs
}
return nil
},
Expand Down
6 changes: 3 additions & 3 deletions cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

var (
ErrFlagNotImplemented error = errors.New("flag not implemented yet")
ErrBadUsageSetCmd error = errors.New("bad usage of set command")
ErrFlagNotImplemented = errors.New("flag not implemented yet")
ErrBadUsageSetCmd = errors.New("bad usage of set command")
)

var setCmd = &cobra.Command{
Expand All @@ -26,7 +26,7 @@ var setCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
interactiveFlag, _ := cmd.Flags().GetBool("i") // TODO: Implement this
if interactiveFlag {
fmt.Println("Not implemented yet")
cmd.SilenceUsage = true
return ErrFlagNotImplemented
}
if len(args) != 2 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var statusCmd = &cobra.Command{
Use: "status",
Short: "Get the status of a project",
Long: `Query the database for the status of a project.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
var alias string
if len(args) != 1 {
fmt.Println("Please provide a project name")
Expand Down
Loading

0 comments on commit 0cb5ae6

Please sign in to comment.