-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add version and update command
- Loading branch information
1 parent
3b06906
commit 977f10e
Showing
9 changed files
with
145 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/nousefreak/projecthelper/internal/pkg/repo" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func getUpdateCmd() *cobra.Command { | ||
updateCmd := &cobra.Command{ | ||
Use: "update", | ||
Short: "update command", | ||
Long: `update command`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
baseDir := getBaseDir() | ||
repoPaths, err := repo.GetRepoPaths(baseDir) | ||
if err != nil { | ||
logrus.Fatal(fmt.Errorf("failed to get repo paths: %w", err)) | ||
} | ||
|
||
cmds := []string{} | ||
for _, repoPath := range repoPaths { | ||
cmds = append(cmds, fmt.Sprintf("(echo \"Updating %s\" && cd %s && git fetch -q)", repoPath, filepath.Join(baseDir, repoPath))) | ||
} | ||
|
||
fmt.Fprint(CmdOutput, strings.Join(cmds, " ; ")) | ||
}, | ||
} | ||
return updateCmd | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package command | ||
|
||
import ( | ||
"runtime/debug" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
||
var ( | ||
Version string | ||
Commit string | ||
Date string | ||
) | ||
|
||
func getVersionCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version number", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" { | ||
Version = info.Main.Version | ||
Commit = info.Main.Sum | ||
} | ||
logrus.Infof("version: \t %s", Version) | ||
logrus.Infof("commit: \t %s", Commit) | ||
logrus.Infof("date: \t %s", Date) | ||
}, | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package repo | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func GetRepoPaths(baseDir string) ([]string, error) { | ||
result := []string{} | ||
if err := filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return fmt.Errorf("failed to walk path %s: %w", path, err) | ||
} | ||
if !info.IsDir() { | ||
return nil | ||
} | ||
relPath, err := filepath.Rel(baseDir, path) | ||
if err != nil { | ||
return fmt.Errorf("failed to get relative path for %s: %w", path, err) | ||
} | ||
if info.Name() != ".git" { | ||
return nil | ||
} | ||
|
||
result = append(result, filepath.Dir(relPath)) | ||
|
||
return err | ||
}); err != nil { | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/nousefreak/projecthelper/internal/pkg/command" | ||
) | ||
|
||
var ( | ||
version = "dev" | ||
commit = "none" | ||
date = "unknown" | ||
) | ||
|
||
func main() { | ||
command.Version = version | ||
command.Commit = commit | ||
command.Date = date | ||
|
||
command.Execute() | ||
} |