Skip to content

Commit

Permalink
Use filepath.Join for defining paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
madrix01 committed Oct 1, 2021
1 parent a00bc95 commit ef00321
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 59 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ release:
@GOOS=linux go build -o bin/linux/bare main.go
@GOOS=darwin go build -o bin/darwin/bare main.go
@GOOS=windows go build -o bin/windows/bare.exe main.go
# tar -czvf bare.tar.gz ./bin
# zip bare.zip ./bin

nightly:
go build -o bin/baren main.go
Binary file modified bin/bare
Binary file not shown.
Binary file modified bin/baren
Binary file not shown.
5 changes: 3 additions & 2 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bare/utils"
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
)
Expand All @@ -29,8 +30,8 @@ func addBare() {
parser.Parser(recipePath)
barePath := parser.BareObj.BarePath
for _, objPath := range parser.BareObj.Include {
sourcePath := "./" + objPath
destiPath := barePath + "/" + objPath
sourcePath := filepath.Join(".", objPath)
destiPath := filepath.Join(barePath, objPath)
err := utils.CopyFileDirectory(sourcePath, destiPath)
if err != nil {
fmt.Print(styles.InitError.Render("[Error] "), styles.AddFileStlyle.Render(objPath))
Expand Down
11 changes: 6 additions & 5 deletions cmd/bareinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -38,8 +39,8 @@ func bareInit(bareName string) {
currDir, _ := os.Getwd()
homePath := os.Getenv("HOME")

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

if bareFolderExsists {
fmt.Println(styles.InitError.Render("[Error] Bare with similar name exsists"))
Expand All @@ -48,22 +49,22 @@ func bareInit(bareName string) {
if !recipeFileExsists {
newBare := parser.Bare{
BareName: bareName,
BarePath: homePath + "/.bare/" + bareName,
BarePath: filepath.Join(homePath, ".bare", bareName),
Include: []string{"recipe.json"},
}
res, err := json.MarshalIndent(newBare, "", " ")
if err != nil {
log.Fatal(err)
}
recipeErr := ioutil.WriteFile(currDir+"/recipe.json", res, 0644)
recipeErr := ioutil.WriteFile(filepath.Join(currDir, "recipe.json"), res, 0644)
if recipeErr != nil {
fmt.Println(styles.InitError.Render("[Error] Cannot create recipe.json file"))
} else {
fmt.Println(styles.InitSuccess.Render("[Success] Created recipe.json"))
}
}

if err := os.Mkdir(homePath+"/.bare/"+bareName, os.ModePerm); err != nil {
if err := os.Mkdir(filepath.Join(homePath, ".bare", bareName), os.ModePerm); err != nil {
log.Fatal(err)
} else {
fmt.Println(styles.InitSuccess.Render("[Success] Created new bare "), bareName)
Expand Down
18 changes: 0 additions & 18 deletions cmd/compile.go

This file was deleted.

3 changes: 2 additions & 1 deletion cmd/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bare/utils"
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -34,7 +35,7 @@ func includeFiles(objects []string) {
if incMap[objs] {
continue
} else {
if utils.Exists(currDir + "/" + objs) {
if utils.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/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var listCmd = &cobra.Command{

func ListBare() {
fmt.Println(styles.InitStyle.Render("Lists of all the bare"))
barePath := os.Getenv("HOME") + "/.bare"
barePath := filepath.Join(os.Getenv("HOME"), ".bare")

fis, err := ioutil.ReadDir(barePath)

Expand All @@ -52,7 +52,7 @@ func ListBare() {

func ListFileWalk(bareName string) {
fmt.Println(styles.InitStyle.Render("Lists of all the files in"), styles.InitSuccess.Render(bareName))
barePath := os.Getenv("HOME") + "/.bare/" + bareName
barePath := filepath.Join(os.Getenv("HOME"), ".bare", bareName)
printDirectory(barePath, 0)
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ func init() {
}

var rmCmd = &cobra.Command{
Use: "rm",
Short: "delete an exsisting bare" ,
Use: "rm",
Short: "delete an exsisting bare",
Run: func(cmd *cobra.Command, args []string) {
if len(args) >= 1{
if len(args) >= 1 {
rmBare(args)
}else{
} else {
fmt.Println(styles.InitError.Render("Not enought arguments"))
}
},
}

func rmBare(delBares []string ){
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)) {
fmt.Println(styles.InitError.Render("[Deleting] "), bare)
os.RemoveAll(filepath.Join(barePath, bare))
}
}
}
}
7 changes: 4 additions & 3 deletions cmd/touch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bufio"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -34,20 +35,20 @@ func touchFile(touchName, newName string) {
fmt.Println(styles.InitError.Render("No such touch present"))
os.Exit(1)
} else {
if utils.Exists(currDir + "/" + newName) {
if utils.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((barePath + "/" + touchMap[touchName]), currDir+"/"+newName)
utils.CopyFileDirectory(filepath.Join(barePath + "/" + touchMap[touchName]), filepath.Join(currDir, newName))
} else {
os.Exit(0)
}
} else {
utils.CopyFileDirectory((barePath + "/" + touchMap[touchName]), currDir+"/"+newName)
utils.CopyFileDirectory(filepath.Join(barePath ,touchMap[touchName]), filepath.Join(currDir, newName))
}
}
}
11 changes: 6 additions & 5 deletions cmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bare/utils"
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
)
Expand All @@ -24,20 +25,20 @@ var useCmd = &cobra.Command{

func useBare(bareName, desti string) {
currDir, _ := os.Getwd()
barePath := os.Getenv("HOME") + "/.bare"
barePath := filepath.Join(os.Getenv("HOME"), ".bare")

if !utils.Exists(barePath + "/" + bareName) {
if !utils.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(currDir + "/" + desti) {
if utils.Exists(filepath.Join(currDir, desti)) {
fmt.Println(styles.InitError.Render("File name already exsists"))
os.Exit(1)
} else {
utils.CreateIfNotExists(currDir+"/"+desti, 0755)
utils.CopyDirectory((barePath + "/" + bareName), (currDir + "/" + desti))
utils.CreateIfNotExists(filepath.Join(currDir, desti), 0755)
utils.CopyDirectory(filepath.Join(barePath, bareName), filepath.Join(currDir, desti))
}

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "barego",
"version": "0.0.2",
"version": "0.1.0",
"description": "A boilerplate manager cli tool",
"main": "index.js",
"repository": {
Expand Down
14 changes: 0 additions & 14 deletions parser/commands.go

This file was deleted.

0 comments on commit ef00321

Please sign in to comment.