Skip to content

added flags functionality to login-command#13

Open
dygland wants to merge 2 commits into
opf:mainfrom
dygland:main
Open

added flags functionality to login-command#13
dygland wants to merge 2 commits into
opf:mainfrom
dygland:main

Conversation

@dygland

@dygland dygland commented May 11, 2026

Copy link
Copy Markdown

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-key to 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

  • Added/updated tests - No added tests, code passes go test -v ./...
  • Added/updated documentation in Lookbook (patterns, previews, etc) - N/A
  • Tested major browsers (Chrome, Firefox, Edge, ...) - N/A

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --host and --api-key flags to op login to bypass interactive prompts.
  • Refactor host parsing so both interactive input and --host use 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

  • parseHostUrlInput removes line breaks but does not trim surrounding whitespace. With --host coming 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 thread cmd/login.go
Comment on lines 99 to +101
if user.Name == "Anonymous" {
printer.ErrorText("no authenticate given")
continue
return
Comment thread cmd/login.go
Comment on lines +121 to +124
if user.Name == "Anonymous" {
printer.ErrorText("no authenticate given")
continue
}
Comment thread README.md

### Login

You are able to login interactively to your openproject instance by running:
Comment thread README.md
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
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants