diff --git a/README.md b/README.md index 73c88e1..de95051 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,11 @@ The DevHub CLI provides powerful theme management capabilities for synchronizing Before using theme commands, you need to initialize your environment: ```bash +# Initialize in current directory devhub theme init + +# Initialize in a new directory +devhub theme init mybrand-corporate-theme ``` This command will: @@ -53,6 +57,8 @@ This command will: - Generate a `.gitignore` file with appropriate exclusions - Create a `devhub.conf.json` configuration file +When specifying a directory, the command will create the directory if it doesn't exist and initialize all configuration files within it. + You'll be prompted to enter: - `DEVHUB_API_KEY` - Your OAuth1 API key - `DEVHUB_API_SECRET` - Your OAuth1 API secret diff --git a/devhub/commands/theme.py b/devhub/commands/theme.py index 3d7a6ef..2dbb046 100644 --- a/devhub/commands/theme.py +++ b/devhub/commands/theme.py @@ -197,13 +197,39 @@ def init_config(): @theme.command() -def init(): +@click.argument('directory', required=False) +def init(directory): """Initialize theme environment configuration.""" - click.echo(click.style('Initializing DevHub environment configuration...', fg='green')) + original_working_dir = os.environ.get('WORKING_DIR', os.getcwd()) + + if directory: + # Check if directory already exists + if os.path.exists(directory): + click.echo(click.style(f'Error: Directory "{directory}" already exists', fg='red')) + return + + # Create the directory + try: + os.makedirs(directory, exist_ok=False) + click.echo(click.style(f'Created directory: {directory}', fg='green')) + except OSError as e: + click.echo(click.style(f'Error creating directory "{directory}": {e}', fg='red')) + return + + # Update WORKING_DIR to the new directory + absolute_directory = os.path.abspath(directory) + os.environ['WORKING_DIR'] = absolute_directory + click.echo(click.style(f'Initializing DevHub environment configuration in {absolute_directory}...', fg='green')) + else: + click.echo(click.style('Initializing DevHub environment configuration...', fg='green')) - init_env() - init_gitignore() - init_config() + try: + init_env() + init_gitignore() + init_config() + finally: + # Restore original WORKING_DIR + os.environ['WORKING_DIR'] = original_working_dir @theme.command()