}
func runEditwork(ctx context.Context, cmd *base.Command, args []string) {
- anyFlags :=
- *editGo != "" ||
- *editJSON ||
- *editPrint ||
- *editFmt ||
- len(workedits) > 0
-
- if !anyFlags {
- base.Fatalf("go: no flags specified (see 'go help work edit').")
- }
-
if *editJSON && *editPrint {
base.Fatalf("go: cannot use both -json and -print")
}
}
}
+ if gowork == "" {
+ base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using -workfile flag)")
+ }
+
+ anyFlags :=
+ *editGo != "" ||
+ *editJSON ||
+ *editPrint ||
+ *editFmt ||
+ len(workedits) > 0
+
+ if !anyFlags {
+ base.Fatalf("go: no flags specified (see 'go help work edit').")
+ }
+
workFile, err := modload.ReadWorkFile(gowork)
if err != nil {
base.Fatalf("go: errors parsing %s:\n%s", base.ShortPath(gowork), err)
}
func runSync(ctx context.Context, cmd *base.Command, args []string) {
- modload.InitWorkfile()
-
modload.ForceUseModules = true
+ modload.InitWorkfile()
+ if modload.WorkFilePath() == "" {
+ base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using -workfile flag)")
+ }
workGraph := modload.LoadModGraph(ctx, "")
_ = workGraph
modload.InitWorkfile()
gowork = modload.WorkFilePath()
+ if gowork == "" {
+ base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using -workfile flag)")
+ }
workFile, err := modload.ReadWorkFile(gowork)
if err != nil {
base.Fatalf("go: %v", err)
--- /dev/null
+! go work use
+stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using -workfile flag\)$'
+
+! go work use .
+stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using -workfile flag\)$'
+
+! go work edit
+stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using -workfile flag\)$'
+
+! go work edit -go=1.18
+stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using -workfile flag\)$'
+
+! go work sync
+stderr '^go: no go\.work file found\n\t\(run ''go work init'' first or specify path using -workfile flag\)$'
+
+-- go.mod --
+module example
+go 1.18
+-- README.txt --
+There is no go.work file here.