Skip to content

Commit

Permalink
feat: restore 時に特定のファイルを除外できるよう対応
Browse files Browse the repository at this point in the history
  • Loading branch information
kotahashihama committed Nov 27, 2024
1 parent 5e71dc9 commit 5101556
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Binary file modified build/pceamless
Binary file not shown.
2 changes: 1 addition & 1 deletion src/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func backupDotfiles(backupDir string) error {
}

excludeMap := make(map[string]bool)
for _, file := range excludeFiles {
for _, file := range backupExcludeFiles {
excludeMap[file] = true
}

Expand Down
16 changes: 11 additions & 5 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ type BackupItem struct {
Selected bool
}

// -e フラグで指定された除外する dotfile のリスト
var excludeFiles []string
var (
// バックアップで使用する除外ファイル群
backupExcludeFiles []string
// リストアで使用する除外ファイル群
restoreExcludeFiles []string
)

// ルートコマンドの定義
var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -65,12 +69,14 @@ var restoreCmd = &cobra.Command{
}

func init() {
// コマンドラインフラグとサブコマンドを設定
rootCmd.AddCommand(backupCmd)
rootCmd.AddCommand(restoreCmd)

// -e フラグの設定
backupCmd.Flags().StringSliceVarP(&excludeFiles, "exclude", "e", []string{}, "バックアップから除外する dotfile")
// backup コマンドの -e フラグ
backupCmd.Flags().StringSliceVarP(&backupExcludeFiles, "exclude", "e", []string{}, "バックアップから除外するdotfile")

// restore コマンドの -e フラグ
restoreCmd.Flags().StringSliceVarP(&restoreExcludeFiles, "exclude", "e", []string{}, "リストアから除外するdotfile")
}

func main() {
Expand Down
13 changes: 13 additions & 0 deletions src/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,22 @@ func restoreDotfiles(backupDir string) error {
return err
}

excludeMap := make(map[string]bool)
for _, file := range restoreExcludeFiles {
name := strings.TrimPrefix(file, ".")
excludeMap[name] = true
excludeMap["."+name] = true
}

homeDir := os.ExpandEnv("$HOME")
for _, entry := range entries {
name := entry.Name()

if excludeMap[name] {
fmt.Printf("INFO: %s はリストアから除外されました\n", name)
continue
}

srcPath := filepath.Join(dotfilesDir, name)
dstPath := filepath.Join(homeDir, name)

Expand Down

0 comments on commit 5101556

Please sign in to comment.