Skip to content

Add CLI client#7

Merged
berggren merged 3 commits intomainfrom
cli
Mar 18, 2026
Merged

Add CLI client#7
berggren merged 3 commits intomainfrom
cli

Conversation

@berggren
Copy link
Copy Markdown
Contributor

@berggren berggren commented Mar 17, 2026

Summary

Initial OpenRelik command-line interface with support for authentication, configuration persistence, and user profile management.

A command line tool to interact with the OpenRelik API

Usage:
  openrelik [command]

Available Commands:
  auth        Manage authentication
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  users       Manage users

Flags:
  -h, --help            help for openrelik
  -o, --output string   Output format (text, json) (default "text")
  -q, --quiet           Suppress all output

Use "openrelik [command] --help" for more information about a command.

Technical Details:

  • CLI Architecture: Established the root command structure using the cobra library, including global flags for output formatting (--output) and a quiet mode (--quiet).
  • Authentication System: Implemented an auth login command that prompts for the server URL and API key. It uses golang.org/x/term to mask sensitive input during the login process.
  • Configuration Management: Created a persistence layer that stores settings and credentials in ~/.openrelik/. It features atomic file writes and enforces restricted file permissions (0600 for files, 0700 for directories) to protect sensitive data.
  • Client Provider Logic: Developed a client initialization sequence that resolves server details and credentials by checking command-line flags, environment variables, and local configuration files in order of priority.
  • User Operations: Added a users me command to fetch and display the authenticated user's profile information.
  • Output Formatting: Built utility functions for standardized output, supporting both a reflection-based text table format and pretty-printed JSON.
  • Testing Suite: Included unit and integration tests for the CLI commands, configuration logic, and utility functions, using a mock API server for command validation.

@berggren berggren requested review from hacktobeer March 17, 2026 22:02
@berggren berggren merged commit c59fda8 into main Mar 18, 2026
3 checks passed
@berggren berggren deleted the cli branch March 18, 2026 09:23
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 this pull request may close these issues.

2 participants