Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/path, tool/file: no error when '**' used as part of glob #3315

Closed
myitcv opened this issue Jul 23, 2024 · 0 comments
Closed

pkg/path, tool/file: no error when '**' used as part of glob #3315

myitcv opened this issue Jul 23, 2024 · 0 comments
Assignees

Comments

@myitcv
Copy link
Member

myitcv commented Jul 23, 2024

What version of CUE are you using (cue version)?

$ cue version
cue version v0.0.0-20240723144244-32013a749daf

go version go1.22.3
      -buildmode exe
       -compiler gc
     CGO_ENABLED 1
          GOARCH arm64
            GOOS linux
             vcs git
    vcs.revision 32013a749dafea2fc7c60fb7d7f0c7e5706d60ba
        vcs.time 2024-07-23T14:42:44Z
    vcs.modified false
cue.lang.version v0.10.0

Does this issue reproduce with the latest release?

Yes

What did you do?

! exec cue cmd x
stderr 'cannot use ** in call to path\.Match'
stderr 'cannot use ** in call to file\.Glob'

-- x_tool.cue --
package x

import (
	"path"
	"strings"

	"tool/cli"
	"tool/file"
)

command: x: {
	print: cli.Print & {
		let res = path.Match("**/blah.json", "blah.json", "unix")
		text: """
			path.Match("**/blah.json", "blah.json", "unix") = \(res)
			"""
	}
	glob: file.Glob & {
		glob: "**/blah.json"
		files: [...string]
	}
	globResult: cli.Print & {
		text: """
		file.Glob(glob: "**/blah.json") => \(strings.Join(glob.files, ", "))
		"""
	}
}

What did you expect to see?

Passing test, for some variation of the error message.

What did you see instead?

> ! exec cue cmd x
[stdout]
path.Match("**/blah.json", "blah.json", "unix") = false
file.Glob(glob: "**/blah.json") =>
FAIL: /tmp/testscript3699288200/repro.txtar/script.txtar:1: unexpected command success

The main motivation for making the use of ** an error in these two situations is to achieve consistency with the embed proposal. If we consistently do not allow ** anywhere there is "glob"-like behaviour then:

  • Nobody can be relying on it accidentally to do something it doesn't know about
  • We can later allow the use of ** in any/all of these places as we introduce support for it.
@mvdan mvdan self-assigned this Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: v0.10.0-alpha.3
Development

No branches or pull requests

2 participants