[engine] Rename Options.Root to Options.Dir

For consistency with Ic9aef678e2cb518a81ff2f36f3bec6fda969675d, rename
the Root field to Dir, since shac now uses git to locate the root
directory, which may differ from (but will always be a parent of) the
directory specified by the Dir field.

Change-Id: I94e6a293691096fa0b52053342a7ea6bab97dcc5
Reviewed-on: https://fuchsia-review.googlesource.com/c/shac-project/shac/+/914337
Reviewed-by: Marc-Antoine Ruel <maruel@google.com>
Fuchsia-Auto-Submit: Oliver Newman <olivernewman@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
diff --git a/internal/cli/base.go b/internal/cli/base.go
index 4d0108c..e5981aa 100644
--- a/internal/cli/base.go
+++ b/internal/cli/base.go
@@ -52,7 +52,7 @@
 		cwd = c.root
 	}
 	return engine.Options{
-		Root:     cwd,
+		Dir:      cwd,
 		AllFiles: c.allFiles,
 		Files:    files,
 		Recurse:  !c.noRecurse,
diff --git a/internal/engine/bench_test.go b/internal/engine/bench_test.go
index 88d0f60..324ef9f 100644
--- a/internal/engine/bench_test.go
+++ b/internal/engine/bench_test.go
@@ -59,7 +59,7 @@
 	copyFile(b, root, "testdata/bench/ctx-emit-finding.star")
 	copyFile(b, root, "testdata/bench/file.txt")
 	r := reportEmitNoPrint{reportNoPrint: reportNoPrint{t: b}}
-	o := Options{Report: &r, Root: root, main: "ctx-emit-finding.star"}
+	o := Options{Report: &r, Dir: root, main: "ctx-emit-finding.star"}
 	b.ReportAllocs()
 	b.ResetTimer()
 	for i := 0; i < b.N; i++ {
@@ -76,7 +76,7 @@
 	copyFile(b, root, "testdata/bench/ctx-emit-artifact.star")
 	copyFile(b, root, "testdata/bench/file.txt")
 	r := reportEmitNoPrint{reportNoPrint: reportNoPrint{t: b}}
-	o := Options{Report: &r, Root: root, main: "ctx-emit-artifact.star"}
+	o := Options{Report: &r, Dir: root, main: "ctx-emit-artifact.star"}
 	b.ReportAllocs()
 	b.ResetTimer()
 	for i := 0; i < b.N; i++ {
@@ -144,7 +144,7 @@
 // benchStarlarkPrint benchmarks a starlark file that calls print().
 func benchStarlarkPrint(b *testing.B, root, name string, all bool, want string) {
 	r := reportPrint{reportNoPrint: reportNoPrint{t: b}}
-	o := Options{Report: &r, Root: root, AllFiles: all, main: name}
+	o := Options{Report: &r, Dir: root, AllFiles: all, main: name}
 	b.ReportAllocs()
 	b.ResetTimer()
 	for i := 0; i < b.N; i++ {
diff --git a/internal/engine/fix_test.go b/internal/engine/fix_test.go
index 8ce6df9..1efae69 100644
--- a/internal/engine/fix_test.go
+++ b/internal/engine/fix_test.go
@@ -113,7 +113,7 @@
 			}
 
 			o := Options{
-				Root:   root,
+				Dir:    root,
 				main:   data[i].name,
 				config: "../config/valid.textproto",
 			}
diff --git a/internal/engine/run.go b/internal/engine/run.go
index 400fc5e..dbb6941 100644
--- a/internal/engine/run.go
+++ b/internal/engine/run.go
@@ -144,10 +144,10 @@
 	// reporting.Get() which returns the right implementation based on the
 	// environment (CI, interactive, etc).
 	Report Report
-	// Root overrides the current working directory, making shac behave as if it
+	// Dir overrides the current working directory, making shac behave as if it
 	// was run in the specified directory. It defaults to the current working
 	// directory.
-	Root string
+	Dir string
 	// Files lists specific files to analyze.
 	Files []string
 	// AllFiles tells to consider all files as affected.
@@ -166,7 +166,7 @@
 
 // Run loads a main shac.star file from a root directory and runs it.
 func Run(ctx context.Context, o *Options) error {
-	root, err := resolveRoot(ctx, o.Root)
+	root, err := resolveRoot(ctx, o.Dir)
 	if err != nil {
 		return err
 	}
diff --git a/internal/engine/run_test.go b/internal/engine/run_test.go
index d0663e2..d856a18 100644
--- a/internal/engine/run_test.go
+++ b/internal/engine/run_test.go
@@ -77,7 +77,7 @@
 				writeFile(t, root, "shac.star", ``)
 				writeFile(t, root, "shac.textproto", "bad")
 				return Options{
-					Root: root,
+					Dir: root,
 				}
 			}(),
 			// The encoding is not deterministic.
@@ -86,7 +86,7 @@
 		{
 			"no shac.star file",
 			Options{
-				Root: t.TempDir(),
+				Dir: t.TempDir(),
 			},
 			// TODO(olivernewman): This error should be more specific, like "no
 			// shac.star file found".
@@ -95,7 +95,7 @@
 		{
 			"no shac.star files (recursive)",
 			Options{
-				Root:    t.TempDir(),
+				Dir:     t.TempDir(),
 				Recurse: true,
 			},
 			"no shac.star files found",
@@ -103,14 +103,14 @@
 		{
 			"nonexistent directory",
 			Options{
-				Root: "!!!this-is-a-file-that-does-not-exist!!!",
+				Dir: "!!!this-is-a-file-that-does-not-exist!!!",
 			},
 			"no such directory: !!!this-is-a-file-that-does-not-exist!!!",
 		},
 		{
 			"not a directory",
 			Options{
-				Root: func() string {
+				Dir: func() string {
 					writeFile(t, scratchDir, "foo.txt", "")
 					return filepath.Join(scratchDir, "foo.txt")
 				}(),
@@ -312,7 +312,7 @@
 		for _, f := range files {
 			absFiles = append(absFiles, filepath.Join(root, f))
 		}
-		o := Options{Report: &r, Root: root, Files: absFiles, Recurse: true}
+		o := Options{Report: &r, Dir: root, Files: absFiles, Recurse: true}
 
 		if err := Run(context.Background(), &o); err != nil {
 			t.Fatal(err)
@@ -370,7 +370,7 @@
 		t.Run(data[i].name, func(t *testing.T) {
 			t.Parallel()
 			r := reportPrint{reportNoPrint: reportNoPrint{t: t}}
-			o := Options{Report: &r, Root: root, main: "shac.star", Files: data[i].files}
+			o := Options{Report: &r, Dir: root, main: "shac.star", Files: data[i].files}
 			err := Run(context.Background(), &o)
 			if err == nil {
 				t.Fatalf("Expected error: %q", data[i].wantErr)
@@ -453,7 +453,7 @@
 		}))
 
 		r := reportPrint{reportNoPrint: reportNoPrint{t: t}}
-		o := Options{Report: &r, Root: root, AllFiles: false, main: "shac.star"}
+		o := Options{Report: &r, Dir: root, AllFiles: false, main: "shac.star"}
 		err := Run(context.Background(), &o)
 		if err == nil {
 			t.Fatal("Expected empty ignore field to be rejected")
@@ -710,7 +710,7 @@
 			r := reportPrint{reportNoPrint: reportNoPrint{t: t}}
 			// Don't specify `main` so it defaults to shac.star.
 			// Specify `recurse` so we use the scm to discover shac.star files.
-			o := Options{Report: &r, Root: root, Recurse: true}
+			o := Options{Report: &r, Dir: root, Recurse: true}
 			if err = Run(context.Background(), &o); err != nil {
 				t.Fatal(err)
 			}
@@ -897,7 +897,7 @@
 	}
 	// Git reports paths separated with "/" even on Windows.
 	dotGit = strings.ReplaceAll(dotGit, string(os.PathSeparator), "/")
-	o := Options{Report: &reportNoPrint{t: t}, Root: root, main: "ctx-scm-affected_files.star"}
+	o := Options{Report: &reportNoPrint{t: t}, Dir: root, main: "ctx-scm-affected_files.star"}
 	if err = Run(context.Background(), &o); err == nil {
 		t.Fatal("expected error")
 	}
@@ -963,7 +963,7 @@
 	runGit(t, root, "add", ".")
 	runGit(t, root, "commit", "-m", "Second commit")
 	r := reportEmitPrint{reportPrint: reportPrint{reportNoPrint: reportNoPrint{t: t}}}
-	o := Options{Report: &r, Root: root, Recurse: true}
+	o := Options{Report: &r, Dir: root, Recurse: true}
 	if err := Run(context.Background(), &o); err != nil {
 		t.Fatal(err)
 	}
@@ -1063,7 +1063,7 @@
 	runGit(t, root, "add", ".")
 	runGit(t, root, "commit", "-m", "Second commit")
 	r := reportEmitPrint{reportPrint: reportPrint{reportNoPrint: reportNoPrint{t: t}}}
-	o := Options{Report: &r, Root: root, Recurse: true}
+	o := Options{Report: &r, Dir: root, Recurse: true}
 	if err := Run(context.Background(), &o); err != nil {
 		t.Fatal(err)
 	}
@@ -1563,7 +1563,7 @@
 		i := i
 		t.Run(data[i].name, func(t *testing.T) {
 			t.Parallel()
-			o := Options{Report: &reportNoPrint{t: t}, Root: root, main: data[i].name}
+			o := Options{Report: &reportNoPrint{t: t}, Dir: root, main: data[i].name}
 			err := Run(context.Background(), &o)
 			if err == nil {
 				t.Fatal("expecting an error")
@@ -1769,7 +1769,7 @@
 		t.Run(data[i].name, func(t *testing.T) {
 			t.Parallel()
 			r := reportEmitNoPrint{reportNoPrint: reportNoPrint{t: t}}
-			o := Options{Report: &r, Root: root, main: data[i].name, config: "../config/valid.textproto"}
+			o := Options{Report: &r, Dir: root, main: data[i].name, config: "../config/valid.textproto"}
 			err := Run(context.Background(), &o)
 			if data[i].err != "" {
 				if err == nil {
@@ -2012,7 +2012,7 @@
 // testStarlarkPrint test a starlark file that calls print().
 func testStarlarkPrint(t testing.TB, root, name string, all bool, want string, files ...string) {
 	r := reportPrint{reportNoPrint: reportNoPrint{t: t}}
-	o := Options{Report: &r, Root: root, AllFiles: all, main: name, Files: files}
+	o := Options{Report: &r, Dir: root, AllFiles: all, main: name, Files: files}
 	if err := Run(context.Background(), &o); err != nil {
 		t.Helper()
 		t.Fatal(err)