Skip to content

Added additional help for CLI and formatting changes #718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/codegate/pipeline/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Available commands:
- `version`: Show the version of CodeGate
- `workspace`: Perform different operations on workspaces
- `custom-instructions`: Set custom instructions for the workspace
"""

NOT_FOUND_TEXT = "Command not found. Use `codegate -h` to see available commands."
Expand Down
94 changes: 53 additions & 41 deletions src/codegate/pipeline/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ async def _add_workspace(self, flags: Dict[str, str], args: List[str]) -> str:
Add a workspace
"""
if args is None or len(args) == 0:
return "Please provide a name. Use `codegate workspace add your_workspace_name`"
return "Please provide a name. Use `codegate workspace add <workspace_name>`"

new_workspace_name = args[0]
if not new_workspace_name:
return "Please provide a name. Use `codegate workspace add your_workspace_name`"
return "Please provide a name. Use `codegate workspace add <workspace_name>`"

try:
ws = await self.workspace_crud.add_workspace(new_workspace_name)
Expand All @@ -204,15 +204,15 @@ async def _rename_workspace(self, flags: Dict[str, str], args: List[str]) -> str
if args is None or len(args) < 2:
return (
"Please provide a name and a new name. "
"Use `codegate workspace rename workspace_name new_workspace_name`"
"Use `codegate workspace rename <workspace_name> <new_workspace_name>`"
)

old_workspace_name = args[0]
new_workspace_name = args[1]
if not old_workspace_name or not new_workspace_name:
return (
"Please provide a name and a new name. "
"Use `codegate workspace rename workspace_name new_workspace_name`"
"Use `codegate workspace rename <workspace_name> <new_workspace_name>`"
)

try:
Expand All @@ -233,11 +233,11 @@ async def _activate_workspace(self, flags: Dict[str, str], args: List[str]) -> s
Activate a workspace
"""
if args is None or len(args) == 0:
return "Please provide a name. Use `codegate workspace activate workspace_name`"
return "Please provide a name. Use `codegate workspace activate <workspace_name>`"

workspace_name = args[0]
if not workspace_name:
return "Please provide a name. Use `codegate workspace activate workspace_name`"
return "Please provide a name. Use `codegate workspace activate <workspace_name>`"

try:
await self.workspace_crud.activate_workspace(workspace_name)
Expand All @@ -254,11 +254,11 @@ async def _archive_workspace(self, flags: Dict[str, str], args: List[str]) -> st
Remove a workspace
"""
if args is None or len(args) == 0:
return "Please provide a name. Use `codegate workspace archive workspace_name`"
return "Please provide a name. Use `codegate workspace archive <workspace_name>`"

workspace_name = args[0]
if not workspace_name:
return "Please provide a name. Use `codegate workspace archive workspace_name`"
return "Please provide a name. Use `codegate workspace archive <workspace_name>`"

try:
await self.workspace_crud.soft_delete_workspace(workspace_name)
Expand All @@ -285,11 +285,11 @@ async def _restore_workspace(self, flags: Dict[str, str], args: List[str]) -> st
Restore an archived workspace
"""
if args is None or len(args) == 0:
return "Please provide a name. Use `codegate workspace restore workspace_name`"
return "Please provide a name. Use `codegate workspace restore <workspace_name>`"

workspace_name = args[0]
if not workspace_name:
return "Please provide a name. Use `codegate workspace restore workspace_name`"
return "Please provide a name. Use `codegate workspace restore <workspace_name>`"

try:
await self.workspace_crud.recover_workspace(workspace_name)
Expand All @@ -306,11 +306,15 @@ async def _delete_archived_workspace(self, flags: Dict[str, str], args: List[str
Hard delete an archived workspace
"""
if args is None or len(args) == 0:
return "Please provide a name. Use `codegate workspace delete-archived workspace_name`"
return (
"Please provide a name. Use `codegate workspace delete-archived <workspace_name>`"
)

workspace_name = args[0]
if not workspace_name:
return "Please provide a name. Use `codegate workspace delete-archived workspace_name`"
return (
"Please provide a name. Use `codegate workspace delete-archived <workspace_name>`"
)

try:
await self.workspace_crud.hard_delete_workspace(workspace_name)
Expand All @@ -328,30 +332,38 @@ def help(self) -> str:
"### CodeGate Workspace\n\n"
"Manage workspaces.\n\n"
"**Usage**: `codegate workspace <command> [args]`\n\n"
"Available commands:\n\n"
"- `list`: List all workspaces\n\n"
" - *args*: None\n\n"
"- `add`: Add a workspace\n\n"
" - *args*:\n\n"
" - `workspace_name`\n\n"
"- `activate`: Activate a workspace\n\n"
" - *args*:\n\n"
" - `workspace_name`\n\n"
"- `archive`: Archive a workspace\n\n"
" - *args*:\n\n"
" - `workspace_name`\n\n"
"- `rename`: Rename a workspace\n\n"
" - *args*:\n\n"
"Available commands:\n"
"- `list`: List all workspaces\n"
" - *args*: None\n"
" - **Usage**: `codegate workspace list`\n"
"- `add`: Add a workspace\n"
" - *args*:\n"
" - `workspace_name`\n"
" - **Usage**: `codegate workspace add <workspace_name>`\n"
"- `activate`: Activate a workspace\n"
" - *args*:\n"
" - `workspace_name`\n"
" - **Usage**: `codegate workspace activate <workspace_name>`\n"
"- `archive`: Archive a workspace\n"
" - *args*:\n"
" - `workspace_name`\n"
" - **Usage**: `codegate workspace archive <workspace_name>`\n"
"- `rename`: Rename a workspace\n"
" - *args*:\n"
" - `workspace_name`\n"
" - `new_workspace_name`\n"
" - **Usage**: `codegate workspace rename <workspace_name> <new_workspace_name>`\n"
"- `list-archived`: List all archived workspaces\n"
" - *args*: None\n"
" - **Usage**: `codegate workspace list-archived`\n"
"- `restore`: Restore an archived workspace\n"
" - *args*:\n"
" - `workspace_name`\n"
" - **Usage**: `codegate workspace restore <workspace_name>`\n"
"- `delete-archived`: Hard delete an archived workspace\n"
" - *args*:\n"
" - `workspace_name`\n"
" - `new_workspace_name`\n\n"
"- `list-archived`: List all archived workspaces\n\n"
" - *args*: None\n\n"
"- `restore`: Restore an archived workspace\n\n"
" - *args*:\n\n"
" - `workspace_name`\n\n"
"- `delete-archived`: Hard delete an archived workspace\n\n"
" - *args*:\n\n"
" - `workspace_name`\n\n"
" - **Usage**: `codegate workspace delete-archived <workspace_name>`\n"
)


Expand Down Expand Up @@ -403,10 +415,10 @@ async def _set_custom_instructions(self, flags: Dict[str, str], args: List[str])
except crud.WorkspaceDoesNotExistError:
return (
f"Workspace custom instructions not updated. "
f"Workspace `{workspace_name}` doesn't exist"
f"Workspace **{workspace_name}** doesn't exist"
)

return f"Workspace `{updated_worksapce.name}` custom instructions updated."
return f"Workspace **{updated_worksapce.name}** custom instructions updated."

async def _show_custom_instructions(self, flags: Dict[str, str], args: List[str]) -> str:
"""
Expand All @@ -421,7 +433,7 @@ async def _show_custom_instructions(self, flags: Dict[str, str], args: List[str]
try:
workspace = await self.workspace_crud.get_workspace_by_name(workspace_name)
except crud.WorkspaceDoesNotExistError:
return f"Workspace `{workspace_name}` doesn't exist"
return f"Workspace **{workspace_name}** doesn't exist"

sysprompt = workspace.custom_instructions
if not sysprompt:
Expand All @@ -444,9 +456,9 @@ async def _reset_custom_instructions(self, flags: Dict[str, str], args: List[str
workspace_name, [""]
)
except crud.WorkspaceDoesNotExistError:
return f"Workspace `{workspace_name}` doesn't exist"
return f"Workspace **{workspace_name}** doesn't exist"

return f"Workspace `{updated_worksapce.name}` custom instructions reset."
return f"Workspace **{updated_worksapce.name}** custom instructions reset."

@property
def help(self) -> str:
Expand All @@ -455,7 +467,7 @@ def help(self) -> str:
"Manage the custom instructionss of workspaces.\n\n"
"*Note*: If you want to update the custom instructions using files please go to the "
"[dashboard](http://localhost:9090).\n\n"
"**Usage**: `codegate custom-instructions -w <workspace_name> <command>`\n\n"
"**Usage**: `codegate custom-instructions -w <workspace_name> <command> [args]`\n\n"
"*args*:\n"
"- `workspace_name`: Optional workspace name. If not specified will use the "
"active workspace\n\n"
Expand Down
4 changes: 2 additions & 2 deletions tests/pipeline/workspace/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ async def test_list_workspaces(mock_workspaces, expected_output):
"args, existing_workspaces, expected_message",
[
# Case 1: No workspace name provided
([], [], "Please provide a name. Use `codegate workspace add your_workspace_name`"),
([], [], "Please provide a name. Use `codegate workspace add <workspace_name>`"),
# Case 2: Workspace name is empty string
([""], [], "Please provide a name. Use `codegate workspace add your_workspace_name`"),
([""], [], "Please provide a name. Use `codegate workspace add <workspace_name>`"),
# Case 3: Successful add
(["myworkspace"], [], "Workspace **myworkspace** has been added"),
],
Expand Down
Loading