Skip to content

Commit 31c7306

Browse files
Merge pull request #2 from RohitRavindra-dev/feature/v1/cleanup
Feature/v1/cleanup
2 parents 57197ec + 732d170 commit 31c7306

7 files changed

Lines changed: 63 additions & 17 deletions

File tree

cmd/cleanup.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/RohitRavindra-dev/devlocal/internal/filesystem"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var cleanupCmd = &cobra.Command{
11+
Use: "cleanup",
12+
Short: "Cleanup devlocal setup",
13+
RunE: func(cmd *cobra.Command, args []string) error {
14+
fmt.Println("Cleaning up setup")
15+
//call revert
16+
// remove devlocal files
17+
fileTeardownError := filesystem.TearDownDevLocalFilesystem()
18+
if fileTeardownError != nil {
19+
return fileTeardownError
20+
}
21+
fmt.Println("Cleanup completed, ciao!")
22+
return nil
23+
},
24+
}
25+
26+
func init() {
27+
rootCmd.AddCommand(cleanupCmd)
28+
}

cmd/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package cmd
33
import (
44
"fmt"
55

6-
"github.com/RohitRavindra-dev/devlocal/internal/configs"
6+
"github.com/RohitRavindra-dev/devlocal/internal/config"
77
"github.com/spf13/cobra"
88
)
99

1010
var versionCmd = &cobra.Command{
1111
Use: "version",
1212
Short: "Print version information",
1313
Run: func(cmd *cobra.Command, args []string) {
14-
fmt.Println("devlocal", configs.Version)
14+
fmt.Println("devlocal", config.Version)
1515
},
1616
}
1717

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package configs
1+
package config
22

33
const (
44
APP_NAME = "devlocal"

internal/config/yaml.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package config
2+
3+
type DevlocalConfigYaml struct {
4+
Version int `yaml:"version"`
5+
Overlook []string `yaml:"overlook"`
6+
Patches []string `yaml:"patches"`
7+
}

internal/configs/yaml.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

internal/filesystem/initialization.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,40 @@ import (
66

77
"os"
88

9-
"github.com/RohitRavindra-dev/devlocal/internal/configs"
9+
"github.com/RohitRavindra-dev/devlocal/internal/config"
1010

1111
"gopkg.in/yaml.v3"
1212
)
1313

1414
func createRootDirectory() error {
15-
_, err := os.Stat(configs.PROJECT_ROOT)
15+
_, err := os.Stat(config.PROJECT_ROOT)
1616
if err == nil {
17-
return fmt.Errorf("%s already exists, please run cleanup", configs.PROJECT_ROOT)
17+
return fmt.Errorf(
18+
"%s is already initialized in this root. "+
19+
"To re-initialize, first run `devlocal cleanup` "+
20+
"and then rerun `devlocal init`",
21+
config.PROJECT_ROOT,
22+
)
1823
}
1924

2025
if !os.IsNotExist(err) {
2126
return err
2227
}
2328

24-
return os.Mkdir(configs.PROJECT_ROOT, 0755)
29+
return os.Mkdir(config.PROJECT_ROOT, 0755)
2530
}
2631

2732
func createConfigFile() error {
2833
err := os.WriteFile(
29-
filepath.Join(configs.PROJECT_ROOT, "config.yaml"),
34+
filepath.Join(config.PROJECT_ROOT, config.CONFIG_FILE_NAME),
3035
[]byte(""),
3136
0644,
3237
)
3338
return err
3439
}
3540

3641
func seedYamlConfigFile() error {
37-
initYamlConfig := configs.DevlocalConfigYaml{
42+
initYamlConfig := config.DevlocalConfigYaml{
3843
Version: 1,
3944
Overlook: []string{},
4045
Patches: []string{},
@@ -46,7 +51,7 @@ func seedYamlConfigFile() error {
4651
return err
4752
}
4853

49-
return os.WriteFile(filepath.Join(configs.PROJECT_ROOT, configs.CONFIG_FILE_NAME), data, 0644)
54+
return os.WriteFile(filepath.Join(config.PROJECT_ROOT, config.CONFIG_FILE_NAME), data, 0644)
5055
}
5156

5257
func InitilizeDevLocalFilesystem() error {

internal/filesystem/teardown.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package filesystem
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/RohitRavindra-dev/devlocal/internal/config"
8+
)
9+
10+
func TearDownDevLocalFilesystem() error {
11+
fmt.Printf("Removing %s and all underlying evidence\n", config.PROJECT_ROOT)
12+
return os.RemoveAll(config.PROJECT_ROOT)
13+
}

0 commit comments

Comments
 (0)