spacelift-io / spacectl

Spacelift client and CLI
MIT License
131 stars 35 forks source link

Issue when using extra args for `spacectl profile login <profile-name>` on initial profile creation #205

Closed FidelusAleksander closed 10 months ago

FidelusAleksander commented 10 months ago

The issue

The command spacectl profile login myorg --endpoint "https://myorg.app.spacelift.io/ works incorrectly on initial spacectl profile creation (no tokens stored yet for that profile).

Why

We wanted to have a pre-cooked script in our repository to allow devs to just run it without having to know/copy-paste the Spacelift endpoint.

Reproduce Case 1

1) Make sure You have no myorg spacectl profile, but You must have other existing profile(s) 2) spacectl profile login myorg --endpoint "https://myorg.app.spacelift.io/ 3) This will redirect You to Your current's profile endpoint instead of "https://myorg.app.spacelift.io/

Reproduce Case 2 (probably not a bug but can we have this a feature?)

1) Delete ALL your spacectl profiles, make sure spacectl profile list shows no profiles 2) spacectl profile login myorg --endpoint "https://myorg.app.spacelift.io/ Results in command is only supported when using an existing API Token profile. Please use **spacectl profile login <alias>** instead

tomasmik commented 10 months ago

Hey, the argument there for myorg should go at the end. This isn't great, but that's how the library we use parses arguments and flags. Let me know if doing something like this helps:

➜  ~ spacectl profile login --endpoint http://tomasmik.app.spacelift.io myorg
[....]
➜  ~ spacectl profile list
Current | Alias          | Endpoint                            | Type
        | a              | http://tomasmik.app.spacelift.io/   | API Key
*       | myorg          | http://tomasmik.app.spacelift.io    | API Token
FidelusAleksander commented 10 months ago

Hey, the argument there for myorg should go at the end. This isn't great, but that's how the library we use parses arguments and flags. Let me know if doing something like this helps:

➜  ~ spacectl profile login --endpoint https://myorg.app.spacelift.io myorg
[....]
➜  ~ spacectl profile list
Current | Alias          | Endpoint                            | Type
        | a              | http://tomasmik.app.spacelift.io/   | API Key
*       | myorg          | http://tomasmik.app.spacelift.io    | API Token

Yeah that works. I guess this error message confused me. command is only supported when using an existing API Token profile. Please use **spacectl profile login <alias>** instead

Thanks

tomasmik commented 10 months ago

Glad I could help. I will close this issue and make an internal note to look at the errors produced by this command.