Skip to content

Commit

Permalink
[#1]: add minimum viable product
Browse files Browse the repository at this point in the history
  • Loading branch information
audipasuatmadi committed Oct 11, 2023
0 parents commit 64de901
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .gitignore
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
25 changes: 25 additions & 0 deletions README.md
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])
Binary file added docs/image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/sample.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/audipasuatmadi/beresbos

go 1.18
7 changes: 7 additions & 0 deletions internal/dto/run_commands_args.go
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
}
48 changes: 48 additions & 0 deletions internal/usecase/run_commands.go
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
}
15 changes: 15 additions & 0 deletions internal/util/cmdutil/getter.go
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
}
13 changes: 13 additions & 0 deletions internal/util/dirutil/abs_dir.go
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
}
28 changes: 28 additions & 0 deletions main.go
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")
}

0 comments on commit 64de901

Please sign in to comment.