Skip to content

Commit 8ad421d

Browse files
authored
Optionally pass a directory path to the init command (#2)
* Optionally pass a directory path to the init command which will create a directory to init into * Updated README
1 parent 0b24418 commit 8ad421d

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,20 @@ The DevHub CLI provides powerful theme management capabilities for synchronizing
4545
Before using theme commands, you need to initialize your environment:
4646

4747
```bash
48+
# Initialize in current directory
4849
devhub theme init
50+
51+
# Initialize in a new directory
52+
devhub theme init mybrand-corporate-theme
4953
```
5054

5155
This command will:
5256
- Create a `.env` file with your DevHub API credentials
5357
- Generate a `.gitignore` file with appropriate exclusions
5458
- Create a `devhub.conf.json` configuration file
5559

60+
When specifying a directory, the command will create the directory if it doesn't exist and initialize all configuration files within it.
61+
5662
You'll be prompted to enter:
5763
- `DEVHUB_API_KEY` - Your OAuth1 API key
5864
- `DEVHUB_API_SECRET` - Your OAuth1 API secret

devhub/commands/theme.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,39 @@ def init_config():
197197

198198

199199
@theme.command()
200-
def init():
200+
@click.argument('directory', required=False)
201+
def init(directory):
201202
"""Initialize theme environment configuration."""
202-
click.echo(click.style('Initializing DevHub environment configuration...', fg='green'))
203+
original_working_dir = os.environ.get('WORKING_DIR', os.getcwd())
204+
205+
if directory:
206+
# Check if directory already exists
207+
if os.path.exists(directory):
208+
click.echo(click.style(f'Error: Directory "{directory}" already exists', fg='red'))
209+
return
210+
211+
# Create the directory
212+
try:
213+
os.makedirs(directory, exist_ok=False)
214+
click.echo(click.style(f'Created directory: {directory}', fg='green'))
215+
except OSError as e:
216+
click.echo(click.style(f'Error creating directory "{directory}": {e}', fg='red'))
217+
return
218+
219+
# Update WORKING_DIR to the new directory
220+
absolute_directory = os.path.abspath(directory)
221+
os.environ['WORKING_DIR'] = absolute_directory
222+
click.echo(click.style(f'Initializing DevHub environment configuration in {absolute_directory}...', fg='green'))
223+
else:
224+
click.echo(click.style('Initializing DevHub environment configuration...', fg='green'))
203225

204-
init_env()
205-
init_gitignore()
206-
init_config()
226+
try:
227+
init_env()
228+
init_gitignore()
229+
init_config()
230+
finally:
231+
# Restore original WORKING_DIR
232+
os.environ['WORKING_DIR'] = original_working_dir
207233

208234

209235
@theme.command()

0 commit comments

Comments
 (0)