func (cr CopyRewriter) Execute(ctx context.Context) error {
	if _, err := os.Stat(cr.Source); err != nil {
		return fmt.Errorf("source not found at %s", cr.Source)
	}
	tempDir, err := ioutil.TempDir("", "repoctl")
	if err != nil {
		return err
	}
	if !cr.KeepTemporary {
		defer func() {
			if _, err = os.Stat(tempDir); err == nil {
				cr.Verbosef("cleaning up temp dir %s", tempDir)
				os.RemoveAll(tempDir)
			}
		}()
	}

	// walk files
	err = filepath.Walk(cr.Source, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}

		base := strings.TrimPrefix(strings.TrimPrefix(path, cr.Source), "/")
		destination := filepath.Join(tempDir, base)

		for _, skipGlob := range cr.SkipGlobs {
			if stringutil.Glob(base, skipGlob) {
				if info.IsDir() {
					cr.Verbosef("%s: skipping dir", base)
					return filepath.SkipDir
				}
				cr.Verbosef("%s: skipping", base)
				return nil
			}
		}

		if info.IsDir() {
			if _, err := os.Stat(destination); err != nil {
				cr.Verbosef("%s", base)
				if !cr.DryRun {
					cr.Debugf("%s: creating %s", base, destination)
					if err = os.MkdirAll(destination, DefaultDirPerms); err != nil {
						return err
					}
				} else {
					cr.Debugf("%s: dry-run; creating dir %s", base, destination)
				}
			}
			return nil
		}

		cr.Verbosef("%s", base)
		if filepath.Ext(path) == ".go" {
			if err := cr.copyGoSourceFile(ctx, destination, path); err != nil {
				return err
			}
		} else {
			if !cr.DryRun {
				if err := Copy(ctx, destination, path); err != nil {
					return err
				}
			}
		}
		return nil
	})

	if !cr.DryRun {
		if cr.RemoveDestination {
			cr.Verbosef("removing destination dir %s", cr.Destination)
			if err := os.RemoveAll(cr.Destination); err != nil {
				return err
			}
		}
		cr.Verbosef("recursively copying %s to %s", tempDir, cr.Destination)
		if err := CopyAll(cr.Destination, tempDir); err != nil {
			return err
		}
	} else {
		cr.Verbosef("%s", "dry-run; skipping final copy")
	}
	return nil
}
// Execute is the command body.
Execute is the command body.
// Execute is the command body .
func (cr CopyRewriter) Execute(ctx context.Context) error {
	if _, err := os.Stat(cr.Source); err != nil {
		return fmt.Errorf("source not found at %s", cr.Source)
	}
	tempDir, err := ioutil.TempDir("", "repoctl")
	if err != nil {
		return err
	}
	if !cr.KeepTemporary {
		defer func() {
			if _, err = os.Stat(tempDir); err == nil {
				cr.Verbosef("cleaning up temp dir %s", tempDir)
				os.RemoveAll(tempDir)
			}
		}()
	}
	err = filepath.Walk(cr.Source, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		base := strings.TrimPrefix(strings.TrimPrefix(path, cr.Source), "/")
		destination := filepath.Join(tempDir, base)
		for _, skipGlob := range cr.SkipGlobs {
			if stringutil.Glob(base, skipGlob) {
				if info.IsDir() {
					cr.Verbosef("%s: skipping dir", base)
					return filepath.SkipDir
				}
				cr.Verbosef("%s: skipping", base)
				return nil
			}
		}
		if info.IsDir() {
			if _, err := os.Stat(destination); err != nil {
				cr.Verbosef("%s", base)
				if !cr.DryRun {
					cr.Debugf("%s: creating %s", base, destination)
					if err = os.MkdirAll(destination, DefaultDirPerms); err != nil {
						return err
					}
				} else {
					cr.Debugf("%s: dry-run; creating dir %s", base, destination)
				}
			}
			return nil
		}
		cr.Verbosef("%s", base)
		if filepath.Ext(path) == ".go" {
			if err := cr.copyGoSourceFile(ctx, destination, path); err != nil {
				return err
			}
		} else {
			if !cr.DryRun {
				if err := Copy(ctx, destination, path); err != nil {
					return err
				}
			}
		}
		return nil
	})
	if !cr.DryRun {
		if cr.RemoveDestination {
			cr.Verbosef("removing destination dir %s", cr.Destination)
			if err := os.RemoveAll(cr.Destination); err != nil {
				return err
			}
		}
		cr.Verbosef("recursively copying %s to %s", tempDir, cr.Destination)
		if err := CopyAll(cr.Destination, tempDir); err != nil {
			return err
		}
	} else {
		cr.Verbosef("%s", "dry-run; skipping final copy")
	}
	return nil
}
func ( cr CopyRewriter ) Execute ( ctx context . Context ) error { if _ , err := os . Stat ( cr . Source ) ; err != nil { return fmt . Errorf ( " " , cr . Source ) } tempDir , err := ioutil . TempDir ( " " , " " ) if err != nil { return err } if ! cr . KeepTemporary { defer func ( ) { if _ , err = os . Stat ( tempDir ) ; err == nil { cr . Verbosef ( " " , tempDir ) os . RemoveAll ( tempDir ) } } ( ) } err = filepath . Walk ( cr . Source , func ( path string , info os . FileInfo , err error ) error { if err != nil { return err } base := strings . TrimPrefix ( strings . TrimPrefix ( path , cr . Source ) , " " ) destination := filepath . Join ( tempDir , base ) for _ , skipGlob := range cr . SkipGlobs { if stringutil . Glob ( base , skipGlob ) { if info . IsDir ( ) { cr . Verbosef ( " " , base ) return filepath . SkipDir } cr . Verbosef ( " " , base ) return nil } } if info . IsDir ( ) { if _ , err := os . Stat ( destination ) ; err != nil { cr . Verbosef ( " " , base ) if ! cr . DryRun { cr . Debugf ( " " , base , destination ) if err = os . MkdirAll ( destination , DefaultDirPerms ) ; err != nil { return err } } else { cr . Debugf ( " " , base , destination ) } } return nil } cr . Verbosef ( " " , base ) if filepath . Ext ( path ) == " " { if err := cr . copyGoSourceFile ( ctx , destination , path ) ; err != nil { return err } } else { if ! cr . DryRun { if err := Copy ( ctx , destination , path ) ; err != nil { return err } } } return nil } ) if ! cr . DryRun { if cr . RemoveDestination { cr . Verbosef ( " " , cr . Destination ) if err := os . RemoveAll ( cr . Destination ) ; err != nil { return err } } cr . Verbosef ( " " , tempDir , cr . Destination ) if err := CopyAll ( cr . Destination , tempDir ) ; err != nil { return err } } else { cr . Verbosef ( " " , " " ) } return nil }
Execute is the command body.
Execute is the command body .
// walk files