예제 #1
0
파일: sync.go 프로젝트: mildred/doc
func mainCopy(args []string) int {
	f := flag.NewFlagSet("cp", flag.ExitOnError)
	opt_dry_run := f.Bool("n", false, "Dry run")
	opt_quiet := f.Bool("q", false, "Quiet")
	opt_force := f.Bool("f", false, "Force copy even if there are errors")
	opt_dedup := f.Bool("d", false, "Deduplicate files on destination (link files on destination instead of copying them from source if possible)")
	opt_dd := f.Bool("dd", false, "Like -d but also remove duplicate files")
	opt_hash := f.Bool("dc", false, "check hash for files that has been modified on the destination directory when deduplicating")
	opt_from := f.String("from", "", "Specify the source directory")
	opt_to := f.String("to", "", "Specify the destination directory")
	opt_commit := f.Bool("commit", false, "Commit the new hash if it has been computed (appear in both source and destination)")
	opt_2pass := f.Bool("2", false, "Scan before copy in two distinct pass")
	opt_nodocignore := f.Bool("no-docignore", false, "Don't respect .docignore")
	opt_verbose := f.Bool("v", false, "Verbose mode")
	f.Usage = func() {
		fmt.Print(copyUsage)
		f.PrintDefaults()
	}
	f.Parse(args)

	src, dst := findSourceDest(*opt_from, *opt_to, f.Args())
	sync_opts := sync.SyncOptions{
		Preparator: &sync.FilePreparatorOpts{
			Commit:    *opt_commit,
			CheckHash: *opt_hash,
			Bidir:     false,
			DocIgnore: !*opt_nodocignore,
		},
		DryRun:    *opt_dry_run,
		Force:     *opt_force,
		Quiet:     *opt_quiet,
		Dedup:     *opt_dedup || *opt_dd,
		DeleteDup: *opt_dd,
		TwoPass:   *opt_2pass,
		Verbose:   *opt_verbose,
	}
	if sync.Sync(src, dst, sync_opts) > 0 {
		os.Exit(1)
	}
	return 0
}
예제 #2
0
파일: sync.go 프로젝트: mildred/doc
func mainSync(args []string) int {
	f := flag.NewFlagSet("sync", flag.ExitOnError)
	opt_dry_run := f.Bool("n", false, "Dry run")
	opt_quiet := f.Bool("q", false, "Quiet")
	opt_force := f.Bool("f", false, "Force copy even if there are errors")
	opt_from := f.String("from", "", "Specify the source directory")
	opt_to := f.String("to", "", "Specify the destination directory")
	opt_commit := f.Bool("commit", false, "Commit the new hash if it has been computed")
	opt_2pass := f.Bool("2", false, "Scan before copy in two distinct pass")
	opt_nodocignore := f.Bool("no-docignore", false, "Don't respect .docignore")
	opt_verbose := f.Bool("v", false, "Verbose mode")
	f.Usage = func() {
		fmt.Print(syncUsage)
		f.PrintDefaults()
	}
	f.Parse(args)

	src, dst := findSourceDest(*opt_from, *opt_to, f.Args())
	sync_opts := sync.SyncOptions{
		Preparator: &sync.FilePreparatorOpts{
			Commit:    *opt_commit,
			CheckHash: false,
			Bidir:     true,
			DocIgnore: !*opt_nodocignore,
		},
		DryRun:    *opt_dry_run,
		Force:     *opt_force,
		Quiet:     *opt_quiet,
		Dedup:     false,
		DeleteDup: false,
		TwoPass:   *opt_2pass,
		Verbose:   *opt_verbose,
	}
	if sync.Sync(src, dst, sync_opts) > 0 {
		os.Exit(1)
	}
	return 0
}