Skip to content

Commit

Permalink
Merge pull request #228 from pieces-app/fix-onboarding
Browse files Browse the repository at this point in the history
fix onboarding if PiecesOS is not running
  • Loading branch information
bishoy-at-pieces authored Jan 9, 2025
2 parents 67117db + 2f5d662 commit c8c0187
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 43 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

# <p align="center"> Pieces Python CLI Tool

<p align="center"> This is a comprehensive command-line interface (CLI) tool designed to interact seamlessly with Pieces OS. It provides a range of functionalities such as asset management, application interaction, and integration with various Pieces OS features.
<p align="center"> This is a comprehensive command-line interface (CLI) tool designed to interact seamlessly with PiecesOS. It provides a range of functionalities such as asset management, application interaction, and integration with various PiecesOS features.

</p>

##### <p align="center"> [Website](https://pieces.app/)[Pieces OS Documentation](https://docs.pieces.app/)[Pieces Python CLI Documentation](https://docs.pieces.app/extensions-plugins/cli)
##### <p align="center"> [Website](https://pieces.app/)[PiecesOS Documentation](https://docs.pieces.app/)[Pieces Python CLI Documentation](https://docs.pieces.app/extensions-plugins/cli)
</p>

[![Introducing CLI](https://img.youtube.com/vi/kAgwHMxWY8c/0.jpg)](https://www.youtube.com/watch?v=kAgwHMxWY8c)

## Important

Make sure you have [**Pieces OS**](https://docs.pieces.app/installation-getting-started/what-am-i-installing) installed in order to run the Pieces CLI tool.
Make sure you have [**PiecesOS**](https://docs.pieces.app/installation-getting-started/what-am-i-installing) installed in order to run the Pieces CLI tool.

#### Operating System Support
The Pieces Python CLI Tool is compatible with various operating systems, ensuring a wide range of usage and adaptability. While it offers full support across most systems, specific features might have varied performance based on the OS environment.
Expand All @@ -27,7 +27,7 @@ The CLI Supports
## Installing
To get started with the Pieces Python CLI Tool, you need to:

1. Ensure Pieces OS is installed and running on your system.
1. Ensure PiecesOS is installed and running on your system.
2. Install the Python package:

```bash
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "pieces-cli"
version = "1.3.1"
description = "A powerful cli tool to interact with the Pieces OS "
description = "A powerful cli tool to interact with PiecesOS "
authors = ["Pieces <development@pieces.app>"]
readme = "README.md"
homepage = "https://pieces.app"
Expand All @@ -22,7 +22,6 @@
[tool.poetry.group.dev.dependencies]
pytest = "^8.0.0"
pyinstaller = "^6.3.0"
# pieces_os_client = {path = "../pieces-os-client-sdk-for-python/dist/pieces_os_client-1.2.7-py3-none-any.whl"}

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
23 changes: 16 additions & 7 deletions src/pieces/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def add_subparsers(self):
ask_parser.set_defaults(func=ask_stream.ask)

# Subparser for the 'version' command
version_parser = self.command_parser.add_parser('version', help='Gets version of Pieces OS')
version_parser = self.command_parser.add_parser('version', help='Gets version of PiecesOS')
version_parser.set_defaults(func=version)

# Subparser for Search
Expand All @@ -82,11 +82,11 @@ def add_subparsers(self):
help_parser.set_defaults(func=lambda **kwargs: print_help())

# Subparser for the 'login' command
login_parser = self.command_parser.add_parser('login', help='Login to pieces os')
login_parser = self.command_parser.add_parser('login', help='Login to PiecesOS')
login_parser.set_defaults(func=sign_in)

# Subparser for the 'logout' command
logout_parser = self.command_parser.add_parser('logout', help='Logout from pieces os')
logout_parser = self.command_parser.add_parser('logout', help='Logout from PiecesOS')
logout_parser.set_defaults(func=sign_out)


Expand Down Expand Up @@ -126,9 +126,13 @@ def add_subparsers(self):
contribute_parser.set_defaults(func=contribute)

# Subparser for the 'install' command
install_parser = self.command_parser.add_parser('install', help='Install the Pieces OS')
install_parser = self.command_parser.add_parser('install', help='Install PiecesOS')
install_parser.set_defaults(func=install_pieces_os)

# Subparser for the 'install' command
install_parser = self.command_parser.add_parser('open', help='Opens PiecesOS')
install_parser.set_defaults(func=lambda **kwargs:Settings.pieces_client.open_pieces_os())


def run(self):
try:
Expand All @@ -138,17 +142,22 @@ def run(self):
return

config = ConfigCommands.load_config()


onboarded = config.get("onboarded", False)

if not config.get("skip_onboarding", False) and not Settings.pieces_client.application.onboarded:

if not config.get("skip_onboarding", False) and not onboarded:
res = input("It looks like this is your first time using the Pieces CLI.\nWould you like to start onboarding (y/n/skip)? ")
if res.lower() == "y":
return onboarding_command()
elif res.lower() == "skip":
config["skip_onboarding"] = True
ConfigCommands.save_config(config)

# Check if the command needs Pieces OS or not
if arg not in ['help',"-v","--version","onboarding","install", "feedback", "contribute"]:

# Check if the command needs PiecesOS or not
if arg not in ['help',"-v","--version","install","onboarding", "feedback", "contribute","open"]:
Settings.startup()

args = self.parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion src/pieces/commands/cli_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def loop(**kwargs):
print(
f"Operating System: {platform.platform()}\n",
f"Python Version: {sys.version.split()[0]}\n",
f"Pieces OS Version: {Settings.pieces_os_version}\n",
f"PiecesOS Version: {Settings.pieces_os_version}\n",
f"Pieces CLI Version: {__version__}\n",
f"Application: {Settings.pieces_client.application.name.value if Settings.pieces_client.application else 'Unknown'}"
)
Expand Down
10 changes: 5 additions & 5 deletions src/pieces/commands/install_pieces_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def install_pieces_os(**kwargs):
"""
Install Pieces OS based on the platform
Install PiecesOS based on the platform
"""

if Settings.pieces_client.local_os == "WINDOWS":
Expand Down Expand Up @@ -33,14 +33,14 @@ def install_pieces_os(**kwargs):
)
script = f"""
TMP_PKG_PATH="/tmp/Pieces-OS-Launch.pkg"
echo "Downloading Pieces OS .pkg file from {pkg_url}..."
echo "Downloading PiecesOS .pkg file from {pkg_url}..."
curl -L "{pkg_url}" -o "$TMP_PKG_PATH"
if [ -f "$TMP_PKG_PATH" ]; then
echo "Pieces OS Download successful, installing the package..."
echo "PiecesOS Download successful, installing the package..."
open "$TMP_PKG_PATH"
echo "Pieces OS Installation complete."
echo "PiecesOS Installation complete."
else
echo "Failed to download and install Pieces OS."
echo "Failed to download and install PiecesOS."
fi
"""
os.system(script)
Expand Down
13 changes: 9 additions & 4 deletions src/pieces/commands/onboarding.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import ABC
from logging import config
from typing import Callable
import pyperclip
from rich.markdown import Markdown
Expand All @@ -13,6 +14,7 @@
import sys

from pieces.commands.cli_loop import run_command, extract_text
from pieces.commands.config_command import ConfigCommands
from pieces.settings import Settings

def get_prompt():
Expand Down Expand Up @@ -148,10 +150,10 @@ def onboarding_command(**kwargs):
console.print("Whenever you want to exit the onboarding flow type `exit`.")

if not Settings.pieces_client.open_pieces_os():
console.print("❌ Pieces OS is not running")
console.print("❌ PiecesOS is not running")
console.print(
Markdown(
"**Pieces OS** is a **required** background service"
"**PiecesOS** is a **required** background service"
" that powers the Pieces CLI and all other Pieces Integrations such as:\n\n"
"- **VS Code**\n"
"- **JetBrains**\n"
Expand All @@ -171,12 +173,12 @@ def onboarding_command(**kwargs):
)

OnboardingCommandStep(
"To install Pieces OS run `pieces install`",
"To install PiecesOS run `pieces install`",
"pieces install"
).run(console)

else:
console.print("✅ Pieces OS is running")
console.print("✅ PiecesOS is running")

Settings.startup()

Expand All @@ -193,5 +195,8 @@ def onboarding_command(**kwargs):
console.print(Markdown("You are now a `10x` more productive developer with Pieces."))
console.print("For more information visit https://docs.pieces.app/extensions-plugins/cli")
Settings.pieces_client.connector_api.onboarded(Settings.pieces_client.application.id, True)
config = ConfigCommands.load_config()
config["onboarded"] = True
ConfigCommands.save_config(config)


10 changes: 5 additions & 5 deletions src/pieces/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ def server_startup_failed():
print()
print("############################")
print()
print("Please make sure Pieces OS is running and up-to-date")
print("Please make sure PiecesOS is running and up-to-date")
print()
print("Or, to install Pieces OS, please visit this link:")
print("Or, to install PiecesOS, please visit this link:")
print_pieces_os_link()
print()
print("############################")
print()


def print_version_details(pos_version,cli_version):
print(f"Pieces OS Version: {pos_version}")
print(f"PiecesOS Version: {pos_version}")
print(f"CLI Version: {cli_version}")

def print_pieces_os_link():
Expand Down Expand Up @@ -109,12 +109,12 @@ def print_help():
print(" Login - Login to pieces")
print(" Logout - Logout from pieces")
print()
print(" version - Gets version of Pieces OS and the version of the cli tool")
print(" version - Gets version of PiecesOS and the version of the cli tool")
print(" help - Show this help message")
print(" onboarding - Start the onboarding process")
print(" feedback - Send feedback to Pieces")
print(" contribute - Contribute to Pieces CLI")
print(" install - Install Pieces OS")
print(" install - Install PiecesOS")
print()

def print_asset_details(asset:"BasicAsset"):
Expand Down
6 changes: 3 additions & 3 deletions src/pieces/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,20 @@ def startup(cls):

@classmethod
def version_check(cls):
"""Check the version of the pieces os in the within range"""
"""Check if the version of PiecesOS is compatible"""
cls.pieces_os_version = cls.pieces_client.version
result = VersionChecker(cls.PIECES_OS_MIN_VERSION,cls.PIECES_OS_MAX_VERSION,cls.pieces_os_version).version_check()

# Check compatibility
if result.update == UpdateEnum.Plugin:
print("Please update your cli-agent tool. It is not compatible with the current Pieces OS version")
print("Please update your cli-agent tool. It is not compatible with the current PiecesOS version")
print()
print("https://pypi.org/project/pieces-cli/")
print()
print_version_details(cls.pieces_os_version, __version__)
sys.exit(2)
elif result.update == UpdateEnum.PiecesOS:
print("Please update Pieces OS. It is not compatible with the current cli-agent version")
print("Please update PiecesOS. It is not compatible with the current cli-agent version")
print()
print_pieces_os_link()
print()
Expand Down
2 changes: 1 addition & 1 deletion src/pieces/wrapper/basic_identifier/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, pieces_client: "PiecesClient", tag: "Tag") -> None:
Initializes a BasicTag instance.
Args:
- tag (Tag): Pieces OS tag object
- tag (Tag): PiecesOS tag object
"""
self.tag = tag
self.pieces_client = pieces_client
Expand Down
4 changes: 2 additions & 2 deletions src/pieces/wrapper/basic_identifier/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BasicUser(Basic):
Attributes:
user_profile: The profile of the user.
pieces_client: The client used to interact with the pieces OS API.
pieces_client: The client used to interact with the PiecesOS API.
"""

user_profile: Optional["UserProfile"] = None
Expand All @@ -23,7 +23,7 @@ def __init__(self, pieces_client) -> None:
Initializes the BasicUser with a pieces client.
Args:
pieces_client: The client used to interact with the pieces OS API.
pieces_client: The client used to interact with the PiecesOS API.
"""
self.pieces_client = pieces_client

Expand Down
4 changes: 2 additions & 2 deletions src/pieces/wrapper/basic_identifier/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ def disassociate_chat(self, chat: "BasicChat"):

def delete(self):
"""
Deletes the website from the Pieces OS.
Deletes the website from PiecesOS
"""
self.pieces_client.websites_api.websites_delete_specific_website(self.website.id)

def _edit_website(self, website: "Website"):
"""
Edits the website in the Pieces OS.
Edits the website in PiecesOS.
Args:
- website: The Website object to edit.
Expand Down
12 changes: 7 additions & 5 deletions src/pieces/wrapper/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def close(cls):
@property
def version(self) -> str:
"""
Returns Pieces OS Version
Returns PiecesOS Version
"""
return self.well_known_api.get_well_known_version()

Expand All @@ -216,9 +216,9 @@ def health(self) -> str:

def open_pieces_os(self) -> bool:
"""
Open Pieces OS
Open PiecesOS
Returns (bool): true if Pieces OS runned successfully else false
Returns (bool): true if PiecesOS launches successfully
"""
if self.is_pieces_running(): return True
if self.local_os == "WINDOWS":
Expand All @@ -232,15 +232,17 @@ def open_pieces_os(self) -> bool:

def is_pieces_running(self,maxium_retries=1) -> bool:
"""
Checks if Pieces OS is running or not
Checks if PiecesOS is running or not
Returns (bool): true if Pieces OS is running
Returns (bool): true if PiecesOS is running
"""
for _ in range(maxium_retries):
try:
with urllib.request.urlopen(f"{self.host}/.well-known/health", timeout=1) as response:
return response.status == 200
except:
if maxium_retries == 1:
return False
time.sleep(1)
return False

Expand Down
2 changes: 1 addition & 1 deletion src/pieces/wrapper/version_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def compare(cls, version1: str, version2: str) -> int:
return 0

def version_check(self) -> 'VersionCheckResult':
"""Check if the Pieces OS version is within the supported range."""
"""Check if the PiecesOS version is within the supported range."""
if self.compare(self.pieces_os_version, self.min_version) < 0:
return VersionCheckResult(False, UpdateEnum.PiecesOS)
elif self.compare(self.pieces_os_version, self.max_version) >= 0:
Expand Down

0 comments on commit c8c0187

Please sign in to comment.