Skip to content

Commit a7d83f3

Browse files
hanshal101rakshitgondwal
authored andcommitted
feat: add clean cmd
Signed-off-by: hanshal101 <122217807+hanshal101@users.noreply.github.com>
1 parent 5e9fb98 commit a7d83f3

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

cmd/clean/clean.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package clean
2+
3+
import (
4+
"fmt"
5+
6+
in "github.com/buildsafedev/bsf/cmd/init"
7+
"github.com/buildsafedev/bsf/cmd/styles"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var CleanCmd = &cobra.Command{
12+
Use: "clean",
13+
Short: "cleans the autogenerated bsf files and directories",
14+
Long: `cleans the autogenerated bsf files and directories.
15+
Cleans bsf.hcl, bsf.lock, /bsf
16+
`,
17+
Run: func(cmd *cobra.Command, args []string) {
18+
clean()
19+
},
20+
}
21+
22+
func clean() {
23+
fmt.Println(styles.SucessStyle.Render("Cleaning autogenerated bsf files and directories"))
24+
in.CleanUp()
25+
}

cmd/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/buildsafedev/bsf/cmd/attestation"
1717
"github.com/buildsafedev/bsf/cmd/build"
18+
"github.com/buildsafedev/bsf/cmd/clean"
1819
"github.com/buildsafedev/bsf/cmd/configure"
1920
"github.com/buildsafedev/bsf/cmd/develop"
2021
"github.com/buildsafedev/bsf/cmd/direnv"
@@ -71,6 +72,7 @@ func Execute() {
7172
rootCmd.AddCommand(configure.ConfigureCmd)
7273
rootCmd.AddCommand(nixgenerate.NixGenCmd)
7374
rootCmd.AddCommand(precheck.PreCheckCmd)
75+
rootCmd.AddCommand(clean.CleanCmd)
7476
}
7577
rootCmd.AddCommand(oci.OCICmd)
7678
rootCmd.AddCommand(dockerfile.DFCmd)

cmd/init/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func GetBSFInitializers() (bsfv1.SearchServiceClient, *hcl2nix.FileHandlers, err
147147
}
148148

149149
// CleanUp removes the bsf config if any error occurs in init process (ctrl+c or any init process stage)
150-
func cleanUp() {
150+
func CleanUp() {
151151
configs := []string{"bsf", "bsf.hcl", "bsf.lock"}
152152

153153
for _, f := range configs {

cmd/init/model.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6464
case tea.KeyMsg:
6565
switch msg.String() {
6666
case "ctrl+c", "q", "esc":
67-
cleanUp()
67+
CleanUp()
6868
return m, tea.Quit
6969
}
7070
}
@@ -76,7 +76,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
7676
}
7777
err = m.processStages(m.stage)
7878
if err != nil {
79-
cleanUp()
79+
CleanUp()
8080
return m, tea.Quit
8181
}
8282
m.stage++

0 commit comments

Comments
 (0)