Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.vscode
.vscode
bin/test
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ or by [gh](https://github.com/cli/cli) :

- Change directory to your local copy:
`cd <folder-name>`
- Setup the project with:
```
make setup
```
- `go mod tidy` (Optional, if bash errors out)
- Build the tool using make:
`make build`
Expand All @@ -24,4 +28,4 @@ Now you will have your tool in `bin` folder, you can try it out following `Readm





6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dev:
nodemon --exec "go fmt && go build -o bin/baren" main.go
nodemon --exec "go fmt && go build -o bin/test/baren" main.go

build:
go build -o bin/bare main.go
Expand All @@ -11,3 +11,7 @@ release:

nightly:
go build -o bin/baren main.go

setup:
echo "Setting up"
go mod download
Binary file modified bin/bare
Binary file not shown.
Binary file removed bin/baren
Binary file not shown.
4 changes: 2 additions & 2 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"bare/parser"
"bare/styles"
"bare/utils"
"bare/utils/osutil"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -32,7 +32,7 @@ func addBare() {
for _, objPath := range parser.BareObj.Include {
sourcePath := filepath.Join(".", objPath)
destiPath := filepath.Join(barePath, objPath)
err := utils.CopyFileDirectory(sourcePath, destiPath)
err := osutil.CopyFileDirectory(sourcePath, destiPath)
if err != nil {
fmt.Print(styles.InitError.Render("[Error] "), styles.AddFileStlyle.Render(objPath))
fmt.Println("")
Expand Down
6 changes: 3 additions & 3 deletions cmd/bareinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"bare/parser"
"bare/styles"
"bare/utils"
"bare/utils/osutil"
"encoding/json"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -39,8 +39,8 @@ func bareInit(bareName string) {
currDir, _ := os.Getwd()
homePath := os.Getenv("HOME")

bareFolderExsists := utils.Exists(filepath.Join(homePath, ".bare", bareName))
recipeFileExsists := utils.Exists(filepath.Join(currDir, "recipe.json"))
bareFolderExsists := osutil.Exists(filepath.Join(homePath, ".bare", bareName))
recipeFileExsists := osutil.Exists(filepath.Join(currDir, "recipe.json"))

if bareFolderExsists {
fmt.Println(styles.InitError.Render("[Error] Bare with similar name exsists"))
Expand Down
7 changes: 4 additions & 3 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package cmd

import (
"bare/styles"
"bare/utils"
"bare/utils/git"
"bare/utils/host"
"bare/utils/osutil"
"fmt"
"os"
"path"
Expand All @@ -30,12 +31,12 @@ func getGithub(args []string) {
currDir, _ := os.Getwd()
targetPath := path.Join(currDir, args[1])

if utils.Exists(path.Join(currDir, args[1])) {
if osutil.Exists(path.Join(currDir, args[1])) {
fmt.Println(styles.InitError.Render("Directory with similar name already exsists !"))
os.Exit(1)
}

if err := utils.CloneRepo(targetPath, utils.CloneOptions{
if err := git.CloneRepo(targetPath, git.CloneOptions{
URL: host.URL(args[0]),
}); err != nil {
fmt.Println(styles.InitError.Render("There was error cloning the repo"), args[0])
Expand Down
4 changes: 2 additions & 2 deletions cmd/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"bare/parser"
"bare/styles"
"bare/utils"
"bare/utils/osutil"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -35,7 +35,7 @@ func includeFiles(objects []string) {
if incMap[objs] {
continue
} else {
if utils.Exists(filepath.Join(currDir, objs)) {
if osutil.Exists(filepath.Join(currDir, objs)) {
parser.BareObj.Include = append(parser.BareObj.Include, objs)
fmt.Println(styles.InitSuccess.Render("[Add] " + objs))
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"bare/styles"
"bare/utils"
"bare/utils/osutil"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -30,7 +30,7 @@ func rmBare(delBares []string) {
fmt.Println(styles.InitStyle.Render("Bare rm"))
barePath := filepath.Join(os.Getenv("HOME"), ".bare")
for _, bare := range delBares {
if utils.Exists(filepath.Join(barePath, bare)) {
if osutil.Exists(filepath.Join(barePath, bare)) {
fmt.Println(styles.InitError.Render("[Deleting] "), bare)
os.RemoveAll(filepath.Join(barePath, bare))
}
Expand Down
35 changes: 35 additions & 0 deletions cmd/temp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cmd

import (
"bare/utils/template"
"fmt"
"log"
"os"
"path/filepath"

"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(templateCmd)
}

var templateCmd = &cobra.Command{
Use: "temp",
Short: "add you current bare to repo",
Long: "same as short for addCmd",
Run: func(cmd *cobra.Command, args []string) {
tempBare()
},
}

func tempBare() {
fmt.Println("Hello world")
bareName := "test"
// currDir, _ := os.Getwd()
barePath := filepath.Join(os.Getenv("HOME"), ".bare", bareName)
err := template.Execute(barePath, "working")
if err != nil {
log.Fatal(err)
}
}
8 changes: 4 additions & 4 deletions cmd/touch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"bare/parser"
"bare/styles"
"bare/utils"
"bare/utils/osutil"
"bufio"
"fmt"
"os"
Expand Down Expand Up @@ -35,20 +35,20 @@ func touchFile(touchName, newName string) {
fmt.Println(styles.InitError.Render("No such touch present"))
os.Exit(1)
} else {
if utils.Exists(filepath.Join(currDir, newName)) {
if osutil.Exists(filepath.Join(currDir, newName)) {
fmt.Println("Already exsists !!")
inp := "n" // warning
reader := bufio.NewReader(os.Stdin)
fmt.Print(styles.Warning.Render("Do you want to override " + newName + " (y/N) > "))
inp, _ = reader.ReadString('\n')
inp = strings.Trim(inp, " ")
if inp == "y" || inp == "Y" {
utils.CopyFileDirectory(filepath.Join(barePath+"/"+touchMap[touchName]), filepath.Join(currDir, newName))
osutil.CopyFileDirectory(filepath.Join(barePath+"/"+touchMap[touchName]), filepath.Join(currDir, newName))
} else {
os.Exit(0)
}
} else {
utils.CopyFileDirectory(filepath.Join(barePath, touchMap[touchName]), filepath.Join(currDir, newName))
osutil.CopyFileDirectory(filepath.Join(barePath, touchMap[touchName]), filepath.Join(currDir, newName))
}
}
}
10 changes: 5 additions & 5 deletions cmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"bare/styles"
"bare/utils"
"bare/utils/osutil"
"fmt"
"os"
"path/filepath"
Expand All @@ -27,18 +27,18 @@ func useBare(bareName, desti string) {
currDir, _ := os.Getwd()
barePath := filepath.Join(os.Getenv("HOME"), ".bare")

if !utils.Exists(filepath.Join(barePath, bareName)) {
if !osutil.Exists(filepath.Join(barePath, bareName)) {
fmt.Println(styles.InitError.Render("Bare doesn't exsist"))
fmt.Println("User `bare list` to get list of all the bares")
os.Exit(1)
}

if utils.Exists(filepath.Join(currDir, desti)) {
if osutil.Exists(filepath.Join(currDir, desti)) {
fmt.Println(styles.InitError.Render("File name already exsists"))
os.Exit(1)
} else {
utils.CreateIfNotExists(filepath.Join(currDir, desti), 0755)
utils.CopyDirectory(filepath.Join(barePath, bareName), filepath.Join(currDir, desti))
osutil.CreateIfNotExists(filepath.Join(currDir, desti), 0755)
osutil.CopyDirectory(filepath.Join(barePath, bareName), filepath.Join(currDir, desti))
}

}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
require (
github.com/go-git/go-git/v5 v5.4.2
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-github/v39 v39.1.0 // indirect
github.com/google/go-github/v39 v39.1.0
github.com/google/go-querystring v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
Expand All @@ -24,7 +24,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.26.0 // indirect
)
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"bare/cmd"
"bare/utils"
"bare/utils/osutil"
)

func main() {
// Check for .bare folder
utils.MakeInitFolder()
osutil.MakeInitFolder()
cmd.Execute()
}
4 changes: 2 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package parser

import (
"bare/utils"
"bare/utils/osutil"
"encoding/json"
"io/ioutil"
"log"
Expand Down Expand Up @@ -42,7 +42,7 @@ func UpdateRecipe() {
if err != nil {
log.Fatal(err)
}
if utils.Exists(recipePath) {
if osutil.Exists(recipePath) {
err = ioutil.WriteFile(recipePath, updatedRecipe, 0644)
if err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion utils/gitutils.go → utils/git/gitutils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package git

import (
"context"
Expand Down
12 changes: 0 additions & 12 deletions utils/host/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ const (
githubStorageURL = "https://codeload.github.com"
)

// func ZipURL(repo string) string {
// var version = "main"

// repo = strings.TrimSuffix(strings.TrimPrefix(repo, "/"), "/")

// zipRegex := regexp.MustCompile(`zip/(\S+)$`)
// if zipRegex.MatchString(repo) {
// return repo
// }

// }

func URL(repo string) string {
githubRegex := regexp.MustCompile(githubURL + `/(\S+)$`)
if githubRegex.MatchString(repo) {
Expand Down
2 changes: 1 addition & 1 deletion utils/copy.go → utils/osutil/fs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package osutil

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion utils/initFolder.go → utils/osutil/init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package osutil

import (
"log"
Expand Down
33 changes: 33 additions & 0 deletions utils/stringutils/stringutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package stringutils

import "io"

type String interface {
io.ReadWriter
String() string
}

func NewString(contents string) String {
s := str(contents)
return &s
}

type str string

func (s *str) Read(buf []byte) (int, error) {
ss := string(*s)
for i := range buf {
buf[i] = byte(ss[i])
}

return len(buf), nil
}

func (s *str) Write(buf []byte) (int, error) {
*s = str(string(*s) + string(buf))
return len(buf), nil
}

func (s *str) String() string {
return string(*s)
}
Loading