added flags functionality to login-command#13
Open
dygland wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds non-interactive support to the op login command by introducing --host and --api-key flags, and documents the new usage in the README to enable scripted/automated logins (e.g., from shell startup files).
Changes:
- Add
--hostand--api-keyflags toop loginto bypass interactive prompts. - Refactor host parsing so both interactive input and
--hostuse the same parsing logic. - Document the new login flags in
README.md.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| README.md | Adds a new “Login” section describing interactive and non-interactive login usage. |
| cmd/login.go | Implements optional --host / --api-key flags and adjusts login flow accordingly. |
Comments suppressed due to low confidence (1)
cmd/login.go:152
parseHostUrlInputremoves line breaks but does not trim surrounding whitespace. With--hostcoming from shell variables or scripts, accidental leading/trailing spaces will cause URL parsing to fail.
printer.Debug(Verbose, "Sanitizing input ...")
input = common.SanitizeLineBreaks(input)
input = strings.TrimSuffix(input, "/")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
99
to
+101
| if user.Name == "Anonymous" { | ||
| printer.ErrorText("no authenticate given") | ||
| continue | ||
| return |
Comment on lines
+121
to
+124
| if user.Name == "Anonymous" { | ||
| printer.ErrorText("no authenticate given") | ||
| continue | ||
| } |
|
|
||
| ### Login | ||
|
|
||
| You are able to login interactively to your openproject instance by running: |
Comment on lines
+101
to
+104
| The login command takes the optional flags `--host` and `--api-key` in order to login non-interactively: | ||
| ```shell | ||
| op login --host https://openproject.org --api-key aaaaabbbbbccccdddddeeeeefffffggggghhhhhiiiiijjjjjkkkkklllllmmmmm | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket
No ticket availalbe for this at https://community.openproject.org/projects/cli/work_packages
What are you trying to accomplish?
Add the flags
--hostand--api-keyto the login command in order to be able to login automatically via .bashrc for example.Screenshots
N/A
What approach did you choose and why?
I needed to be able to sign in automatically on starting a shell, adding the flags to login.go seemed to be the best solution.
Merge checklist
go test -v ./...