-
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.
- Loading branch information
0 parents
commit 64de901
Showing
10 changed files
with
164 additions
and
0 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,25 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
# demo project for testing purposes | ||
demo* | ||
some-module |
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,25 @@ | ||
# Beres Bos!!! | ||
This project was created out of personal bad experience with the repetitiveness of having to "run the same command in different locations sequentially," such as executing 'mvn clean install' in multiple locations. Why not simply define the command once, and then specify the locations where the projects are located? right?... | ||
|
||
# Usage | ||
To use this software, it's pretty easy. Add it to your user / system's `Path` variable, and then run the command as follows: | ||
```bash | ||
beresboss "cmd" ./dir1 ./dir2 ./parentdir1/dir3 /from/root/dir | ||
``` | ||
|
||
A "more" real example: | ||
```bash | ||
beresboss "mvn clean install -T2C --settings \"/path/to/my-settings.xml\"" ./project1 ./module1/project2 ./module1/project3 | ||
``` | ||
|
||
# Demo Example | ||
![Alt text](./docs/sample.gif) | ||
|
||
|
||
# Contributing | ||
Feel free to create a PR! | ||
|
||
![Alt text](./docs/image-1.png) | ||
|
||
# Contributors | ||
* Putu Audi Pasuatmadi ([email protected]) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,3 @@ | ||
module github.com/audipasuatmadi/beresbos | ||
|
||
go 1.18 |
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,7 @@ | ||
package dto | ||
|
||
type RunCommandsArgs struct { | ||
UserCommand string | ||
UserArgs []string | ||
Directories []string | ||
} |
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,48 @@ | ||
package usecase | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/audipasuatmadi/beresbos/internal/dto" | ||
"github.com/audipasuatmadi/beresbos/internal/util/dirutil" | ||
) | ||
|
||
func RunCommands(args dto.RunCommandsArgs) { | ||
var absDir string | ||
var err error | ||
|
||
initialDir, err := os.Getwd() | ||
if err != nil { | ||
log.Fatalf("cannot get initial directory: %+v", err) | ||
} | ||
|
||
for _, directory := range args.Directories { | ||
absDir, err = dirutil.GetAbsDirectory(directory) | ||
if err != nil { | ||
log.Fatalf("cannot get abs directory: %+v", err) | ||
} | ||
|
||
err = os.Chdir(absDir) | ||
if err != nil { | ||
log.Fatalf("error checking out to %s, err :%+v", absDir, err) | ||
} | ||
|
||
cmd := prepareCommand(args) | ||
|
||
err := cmd.Run() | ||
if err != nil { | ||
log.Fatalf("command failed: %v", err) | ||
} | ||
|
||
os.Chdir(initialDir) | ||
} | ||
} | ||
|
||
func prepareCommand(args dto.RunCommandsArgs) *exec.Cmd { | ||
cmd := exec.Command(args.UserCommand, args.UserArgs...) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
return cmd | ||
} |
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,15 @@ | ||
package cmdutil | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
) | ||
|
||
func GetUserCommandsAndDirectories(args []string) (usrCommand string, usrCommandArgs []string, directories []string) { | ||
allCommands := strings.Split(os.Args[1], " ") | ||
|
||
usrCommand = allCommands[0] | ||
usrCommandArgs = allCommands[1:] | ||
directories = os.Args[2:] | ||
return | ||
} |
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,13 @@ | ||
package dirutil | ||
|
||
import "path/filepath" | ||
|
||
func GetAbsDirectory(directory string) (string, error) { | ||
var err error | ||
absDir := directory | ||
if !filepath.IsAbs(absDir) { | ||
absDir, err = filepath.Abs(absDir) | ||
return absDir, err | ||
} | ||
return absDir, 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,28 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/audipasuatmadi/beresbos/internal/dto" | ||
"github.com/audipasuatmadi/beresbos/internal/usecase" | ||
"github.com/audipasuatmadi/beresbos/internal/util/cmdutil" | ||
) | ||
|
||
func main() { | ||
// contributing? add your names here! | ||
log.Println("[main]: starting tool, created by Putu Audi Pasuatmadi") | ||
|
||
if len(os.Args) < 2 { | ||
log.Fatalf("args are [command] [...paths], e.g: beresbos \"mvn clean install -T2C --settings \\\"some-settings\\\"\" ./project1 ./module/project-2") | ||
} | ||
|
||
userCommand, userArgs, directories := cmdutil.GetUserCommandsAndDirectories(os.Args) | ||
usecase.RunCommands(dto.RunCommandsArgs{ | ||
UserCommand: userCommand, | ||
UserArgs: userArgs, | ||
Directories: directories, | ||
}) | ||
|
||
log.Println("[main]: stopping application") | ||
} |