Skip to content

Commit

Permalink
prune_remote_files is not a category (#52)
Browse files Browse the repository at this point in the history
* prune_remote_files is not a category
* Added Upgrade command
  • Loading branch information
jahwag authored Aug 22, 2024
1 parent 4ec53d7 commit 3b556bb
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
82 changes: 82 additions & 0 deletions src/claudesync/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import click
import click_completion
import click_completion.core
import json
import os
import subprocess
import urllib.request
from pkg_resources import get_distribution

from claudesync.cli.chat import chat
from claudesync.config_manager import ConfigManager
Expand Down Expand Up @@ -54,6 +59,83 @@ def status(config):
click.echo(f"{key.replace('_', ' ').capitalize()}: {value or 'Not set'}")


@cli.command()
@click.pass_context
def upgrade(config):
"""Upgrade ClaudeSync to the latest version and reset configuration, preserving sessionKey."""
current_version = get_distribution("claudesync").version

# Check for the latest version
try:
with urllib.request.urlopen(
"https://pypi.org/pypi/claudesync/json"
) as response:
data = json.loads(response.read())
latest_version = data["info"]["version"]

if current_version == latest_version:
click.echo(
f"You are already on the latest version of ClaudeSync (v{current_version})."
)
return
except Exception as e:
click.echo(f"Unable to check for the latest version: {str(e)}")
click.echo("Proceeding with the upgrade process.")

config_path = os.path.expanduser("~/.claudesync/config.json")
session_key = None
session_key_expiry = None

# Read existing configuration
if os.path.exists(config_path):
with open(config_path, "r") as f:
old_config = json.load(f)
session_key = old_config.get("session_key")
session_key_expiry = old_config.get("session_key_expiry")

# Backup existing configuration
backup_path = f"{config_path}.v{current_version}.bak"
os.rename(config_path, backup_path)
click.echo(f"Existing configuration backed up to: {backup_path}")

# Upgrade ClaudeSync
click.echo(f"Upgrading ClaudeSync from v{current_version} to v{latest_version}...")
try:
subprocess.run(["pip", "install", "--upgrade", "claudesync"], check=True)
click.echo("ClaudeSync has been successfully upgraded.")
except subprocess.CalledProcessError:
click.echo(
"Failed to upgrade ClaudeSync. Please try manually: pip install --upgrade claudesync"
)

# Create new configuration with preserved sessionKey
if session_key and session_key_expiry:
new_config = {
"session_key": session_key,
"session_key_expiry": session_key_expiry,
}
with open(config_path, "w") as f:
json.dump(new_config, f, indent=2)
click.echo("New configuration created with preserved sessionKey.")
else:
click.echo("No sessionKey found in the old configuration.")

# Inform user about the upgrade process
click.echo("\nUpgrade process completed:")
click.echo(
f"1. Your previous configuration (v{current_version}) has been backed up."
)
click.echo(
f"2. ClaudeSync has been upgraded from v{current_version} to v{latest_version}."
)
click.echo(
"3. A new configuration has been created, preserving your sessionKey if it existed."
)
click.echo(
"\nPlease run 'claudesync api login' to complete your configuration setup."
)


cli.add_command(api)
cli.add_command(organization)
cli.add_command(project)
Expand Down
2 changes: 1 addition & 1 deletion src/claudesync/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def _get_default_config(self):
"max_file_size": 32 * 1024,
"two_way_sync": False,
"curl_use_file_input": False,
"prune_remote_files": False,
"submodule_detect_filenames": [
"pom.xml",
"build.gradle",
Expand Down Expand Up @@ -99,7 +100,6 @@ def _get_default_config(self):
"go.mod",
],
},
"prune_remote_files": True,
},
}

Expand Down

0 comments on commit 3b556bb

Please sign in to comment.