-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: implement "delete" method * fix lints
- Loading branch information
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/kyoh86/ask" | ||
"github.com/kyoh86/gogh/gogh" | ||
) | ||
|
||
// Delete local projects | ||
func Delete(ctx gogh.Context, primary bool, query string) error { | ||
var walk gogh.Walker = gogh.Walk | ||
if primary { | ||
walk = gogh.WalkInPrimary | ||
} | ||
|
||
var projects []*gogh.Project | ||
if err := gogh.Query(ctx, query, walk, func(p *gogh.Project) error { | ||
projects = append(projects, p) | ||
return nil | ||
}); err != nil { | ||
return err | ||
} | ||
|
||
if len(projects) == 0 { | ||
fmt.Println("Any projects did not matched for", query) | ||
return nil | ||
} | ||
fmt.Println("Deleting projects. Please confirm them and answer by [y/n]") | ||
|
||
for _, p := range projects { | ||
fmt.Print(p.FullPath) | ||
yes, err := ask.YesNo() | ||
if err != nil { | ||
return err | ||
} | ||
if *yes { | ||
if err := os.RemoveAll(p.FullPath); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters