Add dry run flag

main
Mari 3 years ago
parent a719cd25a1
commit e3c99e23b9
  1. 25
      drive-demuxer.go

@ -17,6 +17,7 @@ type TopLevel struct {
CombinedOutput string
RightOutput string
OpenHandles chan int
DryRun bool
}
type Step struct {
@ -96,6 +97,10 @@ func (s *Step) SeparateLeft(child string) {
leftInPath := s.InputPath(child, LEFT)
leftOutPath := s.OutputPath(child, LEFT)
if s.DryRun {
return
}
leftBase := path.Dir(leftOutPath)
err := os.MkdirAll(leftBase, 0755)
if err != nil {
@ -111,6 +116,10 @@ func (s *Step) SeparateRight(child string) {
rightInPath := s.InputPath(child, RIGHT)
rightOutPath := s.OutputPath(child, RIGHT)
if s.DryRun {
return
}
rightBase := path.Dir(rightOutPath)
err := os.MkdirAll(rightBase, 0755)
if err != nil {
@ -127,6 +136,10 @@ func (s *Step) Combine(child string) {
rightInPath := s.InputPath(child, RIGHT)
combinedOutPath := s.OutputPath(child, COMBINED)
if s.DryRun {
return
}
combinedBase := path.Dir(combinedOutPath)
err := os.MkdirAll(combinedBase, 0755)
if err != nil {
@ -144,6 +157,11 @@ func (s *Step) Combine(child string) {
func (s *Step) MakeCombinedDir(child string) {
combinedOutPath := s.OutputPath(child, COMBINED)
if s.DryRun {
return
}
err := os.MkdirAll(combinedOutPath, 0755)
if err != nil {
log.Printf("Failed creating %s: %s\n", combinedOutPath, err)
@ -153,6 +171,11 @@ func (s *Step) MakeCombinedDir(child string) {
func (s *Step) RemoveInputDirs(child string) {
leftInPath := s.InputPath(child, LEFT)
rightInPath := s.InputPath(child, RIGHT)
if s.DryRun {
return
}
err := os.Remove(leftInPath)
if err != nil && !os.IsNotExist(err) {
log.Printf("Failed removing %s: %s\n", leftInPath, err)
@ -332,6 +355,8 @@ func main() {
"combined-output", "./output/combined", "The name of the combined side of the output.")
flag.StringVar(&settings.RightOutput,
"right-output", "./output/right", "The name of the right side of the output.")
flag.BoolVar(&settings.DryRun,
"dry-run", true, "True if no actual operation should be performed.")
flag.Parse()
(&Step{
TopLevel: &settings,

Loading…
Cancel
Save