Skip to content

Commit ded38f3

Browse files
committed
Upgraded to 1.8
1 parent d398d5b commit ded38f3

File tree

8 files changed

+93
-23
lines changed

8 files changed

+93
-23
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.env
1+
.env
2+
/env

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION=1.7
1+
VERSION=1.8

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ scripts:
7777
# Installation
7878
On linux, just run:
7979
```console
80-
sudo curl -s -L https://github.com/SharpSet/sharpdev/releases/download/1.7/install.sh | sudo bash
80+
sudo curl -s -L https://github.com/SharpSet/sharpdev/releases/download/1.8/install.sh | sudo bash
8181
```
8282

8383
## Command Options

sharpdev.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ version: 1.0
22
envfile: .env
33
values:
44
TEST: Values work
5-
_ROOT: /home/coder/code-server/go/src/sharpdev
6-
sharpdev_test: /home/coder/code-server/go/src/sharpdev/internal/sharpdev
5+
_ROOT: /home/coder/projects/sharpdev
6+
sharpdev_test: /home/coder/projects/sharpdev/internal/sharpdev
77

88
setup: |
99
go build -o _ROOT/internal/sharpdev _ROOT/src
@@ -46,6 +46,15 @@ scripts:
4646
sharpdev_test echo5 yay! Duplicates_Work!
4747
sharpdev_test echo2 Extra Args Works!
4848
49+
test_env_download: |
50+
sharpdev_test --url=https://github.com/Sharpz7/dotfiles --envname=k8s
51+
52+
if [ -f ./env/sharpdev.yml ]; then
53+
echo "File Exists"
54+
else
55+
echo "File Does Not Exist"
56+
fi
57+
4958
echo1: echo TEST
5059
echo2: echo "$_ARG1 $_ARG2"
5160
echo3: echo "Env and Parent ${ECHO:-failed}"
@@ -62,3 +71,4 @@ scripts:
6271
sharpdev test_env_sub
6372
sharpdev test_setup
6473
sharpdev_test -ss test_skip_setup
74+
sharpdev_test test_env_download

src/env.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"io"
7+
"net/http"
8+
"os"
9+
"path/filepath"
10+
"strings"
11+
)
12+
13+
func downloadDotFile(dotfileURL, envName string) error {
14+
// Convert GitHub repo URL to the raw content URL
15+
rawURL := strings.Replace(dotfileURL, "github.com", "raw.githubusercontent.com", 1)
16+
rawURL = strings.Replace(rawURL, "/blob", "", 1)
17+
18+
// Construct the URL to the sharpdev.yml in the repository
19+
fileURL := fmt.Sprintf("%s/main/envs/%s/sharpdev.yml", rawURL, envName)
20+
21+
// Send GET request
22+
resp, err := http.Get(fileURL)
23+
if err != nil {
24+
return err
25+
}
26+
defer resp.Body.Close()
27+
28+
// Check the status code
29+
if resp.StatusCode != 200 {
30+
return errors.New("Failed to fetch the file, status: " + resp.Status + ": " + fileURL)
31+
}
32+
33+
// Ensure the destination directory exists
34+
destDir := "./env"
35+
if err := os.MkdirAll(destDir, 0o755); err != nil {
36+
return err
37+
}
38+
39+
// Create the destination file
40+
destPath := filepath.Join(destDir, "sharpdev.yml")
41+
out, err := os.Create(destPath)
42+
if err != nil {
43+
return err
44+
}
45+
defer out.Close()
46+
47+
// Write the response body to the file
48+
_, err = io.Copy(out, resp.Body)
49+
if err != nil {
50+
return err
51+
}
52+
53+
return nil
54+
}

src/files.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ func genFile() {
2626
Scripts: scriptsEx,
2727
Setup: "echo 'Setup command goes here'",
2828
Values: values,
29-
EnvFile: ".env"}
29+
EnvFile: ".env",
30+
}
3031

3132
err := saveFile(testfile)
3233
check(err, "Failed to generate sharpdev.yml")
@@ -43,7 +44,7 @@ func loadFile(parent *bool) config {
4344
var err error
4445
var dir string = "./"
4546

46-
if *parent == true {
47+
if *parent {
4748
// find the parent directory
4849
dir, err = os.Getwd()
4950
check(err, "Failed to get current directory")
@@ -124,7 +125,7 @@ func saveFile(devFile config) error {
124125
// convert string to bytes
125126
yamlBytes := []byte(yamlString)
126127

127-
writeErr := ioutil.WriteFile("./sharpdev.yml", yamlBytes, 0644)
128+
writeErr := ioutil.WriteFile("./sharpdev.yml", yamlBytes, 0o644)
128129

129130
if marshErr != nil || writeErr != nil {
130131
return errors.New("failed to save file")

src/main.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ import (
1313
)
1414

1515
// add a -p flag var as bool
16-
var parent = flag.Bool("p", false, "Use a parent sharpdev.yml file")
17-
var version = flag.Bool("v", false, "Get the version number")
18-
var version2 = flag.Bool("version", false, "Get the version number")
19-
var skipSetup = flag.Bool("ss", false, "Skips using the setup option")
16+
var (
17+
parent = flag.Bool("p", false, "Use a parent sharpdev.yml file")
18+
version = flag.Bool("v", false, "Get the version number")
19+
version2 = flag.Bool("version", false, "Get the version number")
20+
skipSetup = flag.Bool("ss", false, "Skips using the setup option")
21+
dotFile = flag.String("url", "", "The dotfile repo for the sharpdev files. See https://github.com/Sharpz7/dotfiles")
22+
envName = flag.String("envname", "", "The name of sharpdev env to download from")
23+
)
2024

2125
func main() {
2226
var name string
@@ -29,6 +33,15 @@ func main() {
2933
os.Exit(0)
3034
}
3135

36+
// if dotfile is set
37+
if *dotFile != "" {
38+
// Place dotFile/env/envName/sharpdev.yml in ./env
39+
err := downloadDotFile(*dotFile, *envName)
40+
41+
check(err, "Failed to download dotfile")
42+
os.Exit(0)
43+
}
44+
3245
// Load sharpdev file
3346
devFile := loadFile(parent)
3447
if devFile.Version == 0 {
@@ -58,8 +71,6 @@ func main() {
5871
if err != nil {
5972
fmt.Println(err)
6073
}
61-
62-
return
6374
}
6475

6576
// Deals with client Errors
@@ -71,7 +82,7 @@ func check(e error, msg string) {
7182
if os.Getenv("DEV") == "TRUE" {
7283
fmt.Println(e)
7384
}
74-
log.Fatal(msg)
85+
log.Fatal(msg + "\n" + e.Error())
7586
}
7687
}
7788

@@ -106,7 +117,6 @@ Here are all the scripts you have available:
106117
}
107118

108119
func runScript(name string, devFile config) error {
109-
110120
// Check if version is correct
111121
err := checkVersion(devFile)
112122
check(err, "Incorrect version. \nCurrently running 1.0, Script is running "+fmt.Sprint(devFile.Version))
@@ -136,7 +146,6 @@ func runScript(name string, devFile config) error {
136146
}
137147

138148
func runCommand(commStr string, devFile config) error {
139-
140149
if devFile.Setup != "" && !*skipSetup {
141150
// add setup command to commStr
142151
commStr = devFile.Setup + "\n" + commStr
@@ -150,9 +159,6 @@ func runCommand(commStr string, devFile config) error {
150159
commStr = strings.ReplaceAll(commStr, key, val)
151160
}
152161

153-
// Replace "\n" with &&
154-
strings.Replace(commStr, "\n", "&&", -1)
155-
156162
// Run command through OS args
157163
cmd := exec.Command("/bin/sh", "-c", commStr)
158164

@@ -166,7 +172,6 @@ func runCommand(commStr string, devFile config) error {
166172
}
167173

168174
func placeInputArgs(commStr string) string {
169-
170175
if len(flag.Args()) == 0 {
171176
return commStr
172177
}
@@ -196,7 +201,6 @@ func placeInputArgs(commStr string) string {
196201
}
197202

198203
func checkVersion(devFile config) error {
199-
200204
if devFile.Version != 1.0 {
201205
return errors.New("")
202206
}

src/structs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ type config struct {
99
}
1010

1111
// Version Number
12-
var Version float32 = 1.7
12+
var Version float32 = 1.8

0 commit comments

Comments
 (0)