-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from kachick/refactor-go-shared
Refactor go code
- Loading branch information
Showing
8 changed files
with
110 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dotfiles | ||
|
||
import ( | ||
"log" | ||
"os/exec" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
type Cmd struct { | ||
Path string | ||
Args []string | ||
} | ||
|
||
type Commands []Cmd | ||
|
||
func (cmds Commands) ParallelRun() { | ||
wg := &sync.WaitGroup{} | ||
for _, cmd := range cmds { | ||
wg.Add(1) | ||
go func(cmd Cmd) { | ||
defer wg.Done() | ||
output, err := exec.Command(cmd.Path, cmd.Args...).Output() | ||
log.Printf("%s %s\n%s\n", cmd.Path, strings.Join(cmd.Args, " "), output) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
}(cmd) | ||
} | ||
wg.Wait() | ||
} | ||
|
||
func (cmds Commands) SequentialRun() { | ||
for _, cmd := range cmds { | ||
output, err := exec.Command(cmd.Path, cmd.Args...).Output() | ||
log.Printf("%s %s\n%s\n", cmd.Path, strings.Join(cmd.Args, " "), output) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,31 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os/exec" | ||
"strings" | ||
"github.com/kachick/dotfiles" | ||
) | ||
|
||
func main() { | ||
cmds := []struct { | ||
path string | ||
args []string | ||
}{ | ||
{"go", []string{"version"}}, | ||
{"makers", []string{"--version"}}, | ||
{"nix", []string{"--version"}}, | ||
{"dprint", []string{"--version"}}, | ||
{"shellcheck", []string{"--version"}}, | ||
{"shfmt", []string{"--version"}}, | ||
{"typos", []string{"--version"}}, | ||
{"gitleaks", []string{"version"}}, | ||
cmds := dotfiles.Commands{ | ||
{Path: "go", Args: []string{"version"}}, | ||
{Path: "makers", Args: []string{"--version"}}, | ||
{Path: "nix", Args: []string{"--version"}}, | ||
{Path: "dprint", Args: []string{"--version"}}, | ||
{Path: "shellcheck", Args: []string{"--version"}}, | ||
{Path: "shfmt", Args: []string{"--version"}}, | ||
{Path: "typos", Args: []string{"--version"}}, | ||
{Path: "gitleaks", Args: []string{"version"}}, | ||
} | ||
|
||
for _, cmd := range cmds { | ||
output, err := exec.Command(cmd.path, cmd.args...).Output() | ||
log.Printf("%s %s\n%s\n", cmd.path, strings.Join(cmd.args, " "), output) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
cmds.SequentialRun() | ||
} |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0= | ||
github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= | ||
github.com/bmatcuk/doublestar/v4 v4.6.0 h1:HTuxyug8GyFbRkrffIpzNCSK4luc0TY3wzXvzIZhEXc= | ||
github.com/bmatcuk/doublestar/v4 v4.6.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= |
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 dotfiles | ||
|
||
import ( | ||
"io/fs" | ||
"log" | ||
|
||
"github.com/bmatcuk/doublestar/v4" | ||
) | ||
|
||
func GetTyposTargetedRoots() []string { | ||
return []string{ | ||
".", | ||
".github", ".vscode", | ||
"home/.config", "home/.local", "home/.stack", | ||
} | ||
} | ||
|
||
func MustGetAllBash(fsys fs.FS) []string { | ||
bashPaths, err := doublestar.Glob(fsys, "./**/{*.bash,.bash*}") | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
return bashPaths | ||
} | ||
|
||
func MustGetAllNix(fsys fs.FS) []string { | ||
nixPaths, err := doublestar.Glob(fsys, "./**/*.nix") | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
return nixPaths | ||
} |