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

choose.From assignment mismatch #47

Closed
VSngg opened this issue Nov 23, 2022 · 4 comments
Closed

choose.From assignment mismatch #47

VSngg opened this issue Nov 23, 2022 · 4 comments

Comments

@VSngg
Copy link

VSngg commented Nov 23, 2022

When installing both keg@latest and kn@latest I get the following error

go/pkg/mod/github.com/rwxrob/keg@v0.2.4/cmd.go:363:19: assignment mismatch: 3 variables but choose.From returns 2 values
@BuddhiLW
Copy link

If

  • I clone the repository,
  • issue go mod tidy,
  • issue go build cmd/keg/main.go
  • move the main compiled artifact to ~/.local/bin/kg

It then works fine.

For some reason, before you have all the modules installed, choose.From(hits.PrettyLines()) understand the return value as two-valued. As, after all modules install, it understands it as three-valued return (insuring the build).

The error happens here, in the choose.From() assignment, on the default switch:

	Call: func(x *Z.Cmd, args ...string) error {
		if !term.IsInteractive() {
			return titleCmd.Call(x, args...)
		}
		keg, err := current(x.Caller)
		if err != nil {
			return err
		}
		id := args[0]
		if id == "last" {
			if n := Last(keg.Path); n != nil {
				id = n.ID()
			}
		} else {
			_, err := strconv.Atoi(id)
			if err != nil {
				dex, err := ReadDex(keg.Path)
				if err != nil {
					return err
				}
				key := strings.Join(args, " ")
				hits := dex.WithTitleText(key)
				switch len(hits) {
				case 1:
					id = strconv.Itoa(hits[0].N)
				case 0:
					return fmt.Errorf("no titles match: %v", key)
				default:
					i, _, err := choose.From(hits.PrettyLines())
					if err != nil {
						return err
					}
					if i < 0 {
						return nil
					}
					id = strconv.Itoa(hits[i].N)
				}
			}
		}
		path := filepath.Join(keg.Path, id, `README.md`)
		if !fs.Exists(path) {
			return fmt.Errorf("content node (%s) does not exist in %q", id, keg.Name)
		}
		if err := file.Edit(path); err != nil {
			return err
		}
		if err := MakeDex(keg.Path); err != nil {
			return err
		}
		return Publish(keg.Path)
	},

@VSngg
Copy link
Author

VSngg commented Nov 23, 2022

Your instructions didn't work, however if I edit go.mod and update choose module to v0.2.1 the program compiles successfully.

@BuddhiLW
Copy link

BuddhiLW commented Nov 24, 2022

The issue is resolved. He updated the go.mod. Can you confirm it's working there? It's here.

@VSngg
Copy link
Author

VSngg commented Nov 24, 2022

Everything is working. Closing the issue.

@VSngg VSngg closed this as completed Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants