Skip to content

Commit b3c12b3

Browse files
committed
cmd/cue: use default module name for cue mod init
Currently if no arguments are passed to `cue mod init`, it creates a module file with an empty path, which isn't valid. This changes it so it uses an arbitrary module path (`cue.example`) instead. Fixes #3260. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I4388d49ee6ff208cd54ec2bdee724cbd8b6f0ebd Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198143 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 3e9d805 commit b3c12b3

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

cmd/cue/cmd/modinit.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ creating a new module rooted at the current directory. The cue.mod
3434
directory must not already exist. A legacy cue.mod file in the current
3535
directory is moved to the new subdirectory.
3636
37-
A module name is optional, but if it is not given, a package
38-
within the module cannot import another package defined
39-
in the module.
37+
If the module name is not provided, a default module path (cue.example) will be
38+
used.
4039
`,
4140
RunE: mkRunE(c, runModInit),
4241
}
@@ -48,7 +47,7 @@ in the module.
4847
}
4948

5049
func runModInit(cmd *Command, args []string) (err error) {
51-
modulePath := ""
50+
modulePath := "cue.example"
5251
if len(args) > 0 {
5352
if len(args) != 1 {
5453
return fmt.Errorf("too many arguments")

cmd/cue/cmd/testdata/script/modinit_noargs.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exists cue.mod/usr
77
exists cue.mod/pkg
88

99
-- want-module.cue --
10-
module: ""
10+
module: "cue.example"
1111
language: {
1212
version: "$CUE_LANGUAGE_VERSION"
1313
}

0 commit comments

Comments
 (0)