Skip to content

Commit 079d781

Browse files
authored
Merge branch 'Bugsterapp:main' into main
2 parents e859754 + 4b81076 commit 079d781

File tree

5 files changed

+150
-33
lines changed

5 files changed

+150
-33
lines changed

β€ŽCHANGELOG.mdβ€Ž

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to Bugster CLI will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.3.24]
9+
10+
### Changed
11+
- Added flags to `bugster init` for executing automatically.
12+
13+
## [0.3.23]
14+
15+
### Fixed
16+
- Patch update command.
17+
818
## [0.3.22]
919

1020
### Changed
@@ -155,4 +165,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
155165
[0.3.6]: https://github.com/Bugsterapp/bugster-cli/compare/v0.3.0...v0.3.6
156166
[0.3.0]: https://github.com/Bugsterapp/bugster-cli/compare/v0.2.0...v0.3.0
157167
[0.2.0]: https://github.com/Bugsterapp/bugster-cli/compare/v0.1.0...v0.2.0
158-
[0.1.0]: https://github.com/Bugsterapp/bugster-cli/releases/tag/v0.1.0
168+
[0.1.0]: https://github.com/Bugsterapp/bugster-cli/releases/tag/v0.1.0

β€Žbugster/__init__.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Bugster CLI - A command-line interface tool for managing test cases.
33
"""
44

5-
__version__ = "0.3.22"
5+
__version__ = "0.3.24"

β€Žbugster/cli.pyβ€Ž

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,45 @@ def main_callback(
107107

108108

109109
@app.command()
110-
def init():
110+
def init(
111+
api_key: Optional[str] = typer.Option(
112+
None, "--api-key", help="Bugster API key (starts with 'bugster_')"
113+
),
114+
project_name: Optional[str] = typer.Option(
115+
None, "--project-name", help="Name for your project"
116+
),
117+
url: Optional[str] = typer.Option(
118+
None, "--url", help="Base URL of your application (e.g., http://localhost:3000)"
119+
),
120+
user: Optional[str] = typer.Option(
121+
None, "--user", help="Username/email for login credentials"
122+
),
123+
password: Optional[str] = typer.Option(
124+
None, "--password", help="Password for login credentials"
125+
),
126+
credential_name: Optional[str] = typer.Option(
127+
None, "--credential-name", help="Name for the credential entry (default: admin)"
128+
),
129+
no_auth: bool = typer.Option(
130+
False, "--no-auth", help="Skip authentication if API key is already configured"
131+
),
132+
no_credentials: bool = typer.Option(
133+
False, "--no-credentials", help="Skip credential setup entirely"
134+
),
135+
):
111136
"""Initialize Bugster CLI configuration in your project."""
112137
from bugster.commands.init import init_command
113138

114-
init_command()
139+
init_command(
140+
api_key=api_key,
141+
project_name=project_name,
142+
url=url,
143+
user=user,
144+
password=password,
145+
credential_name=credential_name,
146+
no_auth=no_auth,
147+
no_credentials=no_credentials,
148+
)
115149

116150

117151
def _run_tests(

β€Žbugster/commands/init.pyβ€Ž

Lines changed: 101 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from bugster.analytics import track_command
1414
from bugster.clients.http_client import BugsterHTTPClient
15-
from bugster.commands.auth import auth_command
15+
from bugster.commands.auth import auth_command, validate_api_key
1616
from bugster.constants import (
1717
CONFIG_PATH,
1818
TESTS_DIR,
@@ -87,28 +87,52 @@ def generate_project_id(project_name: str) -> str:
8787

8888

8989
@track_command("init")
90-
def init_command():
90+
def init_command(
91+
api_key: str = None,
92+
project_name: str = None,
93+
url: str = None,
94+
user: str = None,
95+
password: str = None,
96+
credential_name: str = None,
97+
no_auth: bool = False,
98+
no_credentials: bool = False,
99+
):
91100
"""Initialize Bugster CLI configuration."""
92101
InitMessages.welcome()
93102

94-
# First check if user is authenticated
95-
api_key = get_api_key()
96-
97-
if not api_key:
103+
# Handle API key authentication
104+
current_api_key = get_api_key()
105+
106+
# Use provided API key or get from storage
107+
if api_key:
108+
# Validate provided API key
109+
if not validate_api_key(api_key):
110+
console.print("[red]Invalid API key. Please check the format and try again.[/red]")
111+
raise typer.Exit(1)
112+
113+
# Save the provided API key
114+
from bugster.utils.user_config import save_api_key
115+
save_api_key(api_key)
116+
current_api_key = api_key
117+
console.print("[green]βœ“ API key saved successfully[/green]")
118+
elif not current_api_key and not no_auth:
98119
logger.info("API key not found, running auth command...")
99120
InitMessages.auth_required()
100121

101122
# Run auth command
102123
auth_command()
103124

104125
# Check if auth was successful
105-
api_key = get_api_key()
126+
current_api_key = get_api_key()
106127

107-
if not api_key:
128+
if not current_api_key:
108129
InitMessages.auth_failed()
109130
raise typer.Exit(1)
110131

111132
InitMessages.auth_success()
133+
elif not current_api_key and no_auth:
134+
console.print("[red]No API key configured and --no-auth flag provided. Please provide --api-key or run without --no-auth.[/red]")
135+
raise typer.Exit(1)
112136

113137
# Check for existing configuration
114138
config_exists, existing_config_path = find_existing_config()
@@ -128,15 +152,21 @@ def init_command():
128152

129153
# Project setup
130154
InitMessages.project_setup()
131-
project_name = Prompt.ask("🏷️ Project name", default=Path.cwd().name)
155+
156+
# Use provided project name or prompt for it
157+
if project_name is None:
158+
project_name = Prompt.ask("🏷️ Project name", default=Path.cwd().name)
159+
else:
160+
console.print(f"🏷️ Project name: {project_name}")
161+
132162
project_path = ""
133163
with contextlib.suppress(Exception):
134164
project_path = get_git_prefix_path()
135165

136166
# Create project via API
137167
try:
138168
with BugsterHTTPClient() as client:
139-
client.set_headers({"x-api-key": api_key})
169+
client.set_headers({"x-api-key": current_api_key})
140170
InitMessages.creating_project()
141171

142172
project_data = client.post(
@@ -155,30 +185,72 @@ def init_command():
155185
project_id = generate_project_id(project_name)
156186

157187
InitMessages.show_project_id(project_id)
158-
base_url = Prompt.ask("\n🌐 Application URL", default="http://localhost:3000")
188+
189+
# Use provided URL or prompt for it
190+
if url is None:
191+
base_url = Prompt.ask("\n🌐 Application URL", default="http://localhost:3000")
192+
else:
193+
base_url = url
194+
console.print(f"🌐 Application URL: {base_url}")
159195

160196
# Credentials setup
161-
InitMessages.auth_setup()
162197
credentials = []
163198

164-
if (
165-
Prompt.ask(
166-
"βž• Would you like to add custom login credentials? (y/n)", default="y"
167-
).lower()
168-
== "y"
169-
):
170-
identifier = Prompt.ask(
171-
"πŸ‘€ Credential name",
172-
default="admin",
173-
)
174-
username = Prompt.ask("πŸ“§ Username/Email")
175-
password = Prompt.ask("πŸ”’ Password", password=True)
176-
177-
credentials.append(create_credential_entry(identifier, username, password))
178-
InitMessages.credential_added()
199+
if no_credentials:
200+
# Skip credentials setup entirely
201+
if user is not None or password is not None or credential_name is not None:
202+
console.print("[red]Error: Cannot use --user, --password, or --credential-name with --no-credentials.[/red]")
203+
raise typer.Exit(1)
204+
else:
205+
console.print("🚫 Skipping credential setup (--no-credentials flag provided)")
179206
else:
180-
credentials.append(create_credential_entry())
181-
InitMessages.using_default_credentials()
207+
InitMessages.auth_setup()
208+
209+
# Determine if we should use custom credentials
210+
use_custom_credentials = False
211+
212+
if user is not None and password is not None:
213+
# Both user and password provided via flags
214+
use_custom_credentials = True
215+
console.print("βœ“ Using provided login credentials")
216+
elif user is not None or password is not None:
217+
# Only one of user/password provided - this is an error
218+
console.print("[red]Error: Both --user and --password must be provided together.[/red]")
219+
raise typer.Exit(1)
220+
else:
221+
# No credentials provided via flags, prompt interactively
222+
if (
223+
Prompt.ask(
224+
"βž• Would you like to add custom login credentials? (y/n)", default="y"
225+
).lower()
226+
== "y"
227+
):
228+
use_custom_credentials = True
229+
230+
if use_custom_credentials:
231+
# Use provided values or prompt for them
232+
if user is not None and password is not None:
233+
# Values provided via flags
234+
identifier = credential_name or "admin"
235+
username = user
236+
password_value = password
237+
console.print(f"πŸ‘€ Credential name: {identifier}")
238+
console.print(f"πŸ“§ Username/Email: {username}")
239+
console.print("πŸ”’ Password: [hidden]")
240+
else:
241+
# Interactive mode
242+
identifier = Prompt.ask(
243+
"πŸ‘€ Credential name",
244+
default="admin",
245+
)
246+
username = Prompt.ask("πŸ“§ Username/Email")
247+
password_value = Prompt.ask("πŸ”’ Password", password=True)
248+
249+
credentials.append(create_credential_entry(identifier, username, password_value))
250+
InitMessages.credential_added()
251+
else:
252+
credentials.append(create_credential_entry())
253+
InitMessages.using_default_credentials()
182254

183255
# Create project structure
184256
InitMessages.project_structure_setup()

β€Žbugster/libs/utils/enums.pyβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class BugsterApiPath(str, Enum):
55
"""Bugster API paths."""
66

7+
TEST_CASES = "/api/v1/test-cases"
78
TEST_CASES_NEW = "/api/v1/test-cases/new"
89
GENERATE_INIT = "/generate/init"
910
GENERATE_CHECK_RESULTS = "/generate/check-results"

0 commit comments

Comments
Β (0)