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

Module rbenv can't export command named same as module. #613

Closed
marcelarie opened this issue Sep 21, 2023 · 3 comments · Fixed by #614
Closed

Module rbenv can't export command named same as module. #613

marcelarie opened this issue Sep 21, 2023 · 3 comments · Fixed by #614

Comments

@marcelarie
Copy link
Contributor

When I try to use the rbenv.nu, using the use path/to/rbenv.nu * as it says on the README, I get the following error:

Error: nu::parser::named_as_module

  × Can't export command named same as the module.
    ╭─[/Users/m.manzanares/clones/fork/nu_scripts/modules/rbenv/rbenv.nu:10:1]
 10 │
 11 │ export def-env rbenv [
    ·                ──┬──
    ·                  ╰── can't export from module rbenv
 12 │     command?: string@'nu-complete rbenv',
    ╰────
  help: Module rbenv can't export command named the same as the module. Either change the module name, or export `main` command.```
@fdncred
Copy link
Collaborator

fdncred commented Sep 21, 2023

Someone probably needs to update the code with the latest syntax.

@marcelarie
Copy link
Contributor Author

In what version was the new syntax implemented? Is there a migration guide?

@marcelarie
Copy link
Contributor Author

marcelarie commented Sep 21, 2023

Is it something like this?

OLD:

# rbenv
export-env { 
    load-env {
        PATH: ($env.PATH | split row (char esep) | prepend [$"($env.HOME)/.rbenv/bin" $"($env.HOME)/.rbenv/shims"])
        RBENV_VERSION: ""
        RBENV_VERSION_OLD: ""
        RBENV_SHELL: "nu"
    }
}

export def-env rbenv [
	command?: string@'nu-complete rbenv',
	...args
] {
    let new_env = if $command in ["rehash", "shell"] {
        # implement each on indiviudaly e.g.
        if $command == "shell" {
            { RBENV_VERSION_OLD: $env.RBENV_VERSION RBENV_VERSION: $args.0 }
        } else {
            error make { msg: $"`($command)` command is not supported yet" }
        }
    } else {
    	if ($command | is-empty) {
    		^rbenv
    	} else {
        	^rbenv $command $args
    	}
        {}
    }
    load-env $new_env
}

def 'nu-complete rbenv' [] {
    ^rbenv help
    | lines
    | where ($it | str starts-with "   ")
    | each {|entry| $entry | split row ' ' | get 0 }
}

NEW:

# rbenv
export-env {
    load-env {
        PATH: ($env.PATH | split row (char esep) | prepend [$"($env.HOME)/.rbenv/bin" $"($env.HOME)/.rbenv/shims"])
        RBENV_VERSION: ""
        RBENV_VERSION_OLD: ""
        RBENV_SHELL: "nu"
    }
}

def rbenv [command?: string, ...args] {
    let new_env = if $command in ["rehash", "shell"] {
        if $command == "shell" {
            { RBENV_VERSION_OLD: $env.RBENV_VERSION RBENV_VERSION: $args.0 }
        } else {
            error make { msg: $"`($command)` command is not supported yet" }
        }
    } else {
        if ($command | is-empty) {
            ^rbenv
        } else {
            ^rbenv $command $args
        }
        {}
    }
    load-env $new_env
}

def 'nu-complete rbenv' [] {
    ^rbenv help
    | lines
    | where ($it | str starts-with "   ")
    | each {|entry| $entry | split row ' ' | get 0 }
}

@amtoine amtoine linked a pull request Sep 21, 2023 that will close this issue
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