Skip to content

Commit

Permalink
feat: support exclude files
Browse files Browse the repository at this point in the history
  • Loading branch information
jonyhy96 committed Oct 17, 2019
1 parent b2be6c1 commit 657ae22
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"log"
"os"
"path/filepath"
Expand All @@ -17,6 +18,7 @@ import (
func init() {
rootCmd.Flags().StringP("file", "f", "", "the replace file filepath e.g. ./keys.json")
rootCmd.Flags().StringP("work", "w", "", "the work path of files you want to replace")
rootCmd.Flags().StringSliceP("exclude", "e", []string{}, "specify exclude file names e.g. go.mod,go.sum")
rootCmd.Flags().StringVar(&fileType, "t", "", "the type of your replace file(default is json)")
rootCmd.MarkFlagRequired("file")
rootCmd.MarkFlagRequired("work")
Expand All @@ -31,11 +33,12 @@ var (
wg = sync.WaitGroup{}
rootCmd = &cobra.Command{
Use: "replacer",
Short: "replacer eplace things for you\n",
Short: "replacer replace things for you\n",
Version: "1.0.0",
Run: func(cmd *cobra.Command, args []string) {
replaceFilePath, _ := cmd.Flags().GetString("file")
workPath, _ := cmd.Flags().GetString("work")
excludedFiles, _ := cmd.Flags().GetStringSlice("exclude")
if fileType == "" {
_replaceMap, err = file.New(defaultFileType).Transform(replaceFilePath)
if err != nil {
Expand All @@ -52,6 +55,14 @@ var (
if strings.Contains(replaceFilePath, info.Name()) {
return nil
}
if len(excludedFiles) > 0 {
for _, filename := range excludedFiles {
if info.Name() == filename {
fmt.Println(filename)
return nil
}
}
}
wg.Add(1)
go func() {
defer wg.Done()
Expand Down

0 comments on commit 657ae22

Please sign in to comment.