Skip to content
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
67 changes: 57 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ A lightweight Python utility to quickly clone, configure, and build CMake projec
- [Configuration](#configuration)
- [Usage](#usage)
- [Single Repository Mode](#single-repository-mode)
- [Mono-Repo Mode](#mono-repo-mode)
- [Profile Mode](#profile-mode-saved-configurations)
- [Mono-Repo Mode](#mono-repository-mode)
- [Profile Mode](#profile-mode)
- [Config Mode](#config-mode)
- [Development](#development)
- [License](#license)

Expand Down Expand Up @@ -75,9 +76,9 @@ pip install git+https://github.com/masonlet/starlet-setup.git

Once installed, you can use the `starlet-setup` command from anywhere.

### ⚠️ Command not found? ⚠️
<details>
<summary><h4>⚠️ Command not found? ⚠️</h4></summary>
If you get an error saying the command is not found, you may need to add Python's user scripts directory to your PATH:
<summary>If you get an error saying the command is not found, you may need to add Python's user scripts directory to your PATH.</summary>

**Find your scripts directory**:
```bash
Expand Down Expand Up @@ -136,9 +137,10 @@ Starlet Setup checks for configuration files in this order:

## Usage

### <a id="single-repository-mode"></a>
<details>
<summary><h3>Single Repository Mode</h3></summary>
<summary>Single Repository Mode</summary>

#### Basic Usage

```bash
Expand Down Expand Up @@ -171,11 +173,14 @@ starlet-setup username/repo --verbose
# Custom CMake args
starlet-setup username/repo --cmake-arg=-DCMAKE_CXX_COMPILER=clang++
```
</details>

<br/>

</details>

### <a id="mono-repository-mode"></a>
<details>
<summary><h3>Mono-Repo Mode</h3></summary>
<summary>Mono-Repo Mode</summary>

#### BUILD_LOCAL Usage
Mono-repo mode sets `BUILD_LOCAL=ON` in the root project's CMakeLists.txt.
Expand Down Expand Up @@ -264,10 +269,14 @@ This structure allows you to:
- Build everything together
- Debug across module boundaries
- Commit changes without digging into build directories

<br/>

</details>

### <a id="profile-mode"></a>
<details>
<summary><h3>Profile Mode (Saved Configurations)</h3></summary>
<summary>Profile Mode (Saved Configurations)</summary>

#### Managing Profiles
```bash
Expand All @@ -292,13 +301,51 @@ starlet-setup username/repo --profile myprofile
# Use a profile with SSH
starlet-setup username/repo --profile myprofile --ssh
```

<br/>

</details>

### <a id="config-mode"></a>
<details>
<summary>Config Mode (Saved Build Settings)</summary>

#### Managing Configs
```bash
# List all saved configurations
starlet-setup --list-configs

# Add a new configuration with flags
starlet-setup --config-add myconfig --ssh --build-type Release --no-build

# Remove a configuration
starlet-setup --config-remove myconfig
```

#### Using Configs
```bash
# Use a saved config
starlet-setup username/repo --config myconfig

# Override specific settings
starlet-setup username/repo --config myconfig --verbose

# Config with mono-repo mode
starlet-setup username/repo --mono-repo --config myconfig --ssh
```

<br/>

</details>


<br/>

## Development

### <a id="development"></a>
<details>
<summary><h3>Developing starlet-setup</h3></summary>
<summary>Development</summary>

### Running Tests

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "starlet-setup"
version = "1.0.2"
version = "1.1.0"
description = "Quick setup for CMake projects"
readme = "README.md"
requires-python = ">=3.6"
Expand Down
26 changes: 20 additions & 6 deletions src/starlet_setup/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

from .cli import parse_args
from .config import create_default_config
from .config import create_default_config, list_configs, add_config, remove_config
from .profiles import list_profiles, add_profile, remove_profile
from .utils import check_prerequisites
from .commands import mono_repo_mode, single_repo_mode
Expand All @@ -19,21 +19,35 @@ def main() -> None:
if args.init_config:
create_default_config()
return

if args.list_configs:
list_configs(args.config)
return
if args.config_add:
new_config = {
'ssh': args.ssh,
'build_type': args.build_type,
'build_dir': args.build_dir,
'mono_dir': args.mono_dir,
'no_build': args.no_build,
'verbose': args.verbose,
'cmake_arg': args.cmake_arg or []
}
add_config(args.config, args.config_add, new_config)
return
if args.config_remove:
remove_config(args.config, args.config_remove)
return
if args.list_profiles:
list_profiles(args.config)
return

if args.profile_add:
add_profile(args.config, args.profile_add)
return

if args.profile_remove:
remove_profile(args.config, args.profile_remove)
return

check_prerequisites(args.verbose)

if args.mono_repo or args.profile:
mono_repo_mode(args)
else:
Expand Down
148 changes: 91 additions & 57 deletions src/starlet_setup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,14 @@

import argparse
from argparse import Namespace
from typing import Any
from .config import get_config_value, load_config


def parse_args() -> Namespace:
"""
Parse command-line arguments for Starlet Setup.

Returns:
Parsed arguments namespace
"""
config, config_path = load_config()

parser = argparse.ArgumentParser(
description="Starlet Setup - Quick setup script for CMake projects",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
Single Repository Mode:
%(prog)s https://github.com/username/repo.git
%(prog)s git@github.com:username/repo.git
%(prog)s username/repo
%(prog)s username/repo --ssh
%(prog)s username/repo --no-build
%(prog)s username/repo --build-dir build_name --build-type Release

Mono-repo Repository Mode:
%(prog)s username/repo --mono-repo
%(prog)s username/repo --mono-repo --ssh --mono-dir my_workspace
%(prog)s username/repo --repos user/lib1 user/lib2 user/lib3

Profile Repository Mode:
%(prog)s username/repo --profile
%(prog)s username/repo --profile myprofile

Profile Management:
%(prog)s --list-profiles
%(prog)s --profile-add myprofile user/lib1 user/lib2 user/lib3
%(prog)s --profile-remove myprofile

Config:
%(prog)s --init-config
"""
)

# Common arguments
def _add_common_args(
parser,
config: dict[str, Any]
) -> None:
parser.add_argument(
'--ssh',
action='store_true',
Expand All @@ -66,14 +29,31 @@ def parse_args() -> Namespace:
help='Additional CMake arguments (e.g., --cmake-arg=-D_BUILD_TESTS=ON). Can be used multiple times.'
)

# Configuration arguments

def _add_config_management_args(parser) -> None:
parser.add_argument(
'--init-config',
action='store_true',
help='Create a default config file in the current directory'
)
parser.add_argument(
'--config-add',
metavar=('NAME'),
help="Add a new config"
)
parser.add_argument(
'--config-remove',
metavar='NAME',
help='Remove a saved configuration'
)
parser.add_argument(
'--list-configs',
action='store_true',
help='List all saved configs'
)

# Profile management arguments

def _add_profile_management_args(parser) -> None:
parser.add_argument(
'--profile-add',
nargs='+',
Expand All @@ -91,7 +71,8 @@ def parse_args() -> Namespace:
help='List all saved profiles'
)

# Build arguments

def _add_build_args(parser, config: dict[str, Any]) -> None:
parser.add_argument(
'-b', '--build-type',
choices=['Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel'],
Expand All @@ -115,14 +96,8 @@ def parse_args() -> Namespace:
help='Clean build directory before building'
)

# Repository argument
parser.add_argument(
'repo',
nargs='?',
help='Repository name (username/repo) or full GitHub URL'
)

# Mono-repo repo mode arguments

def _add_mono_repo_args(parser, config: dict[str, Any]) -> None:
parser.add_argument(
'--mono-repo',
action='store_true',
Expand All @@ -147,20 +122,79 @@ def parse_args() -> Namespace:
help='Use saved profile for library repositories (uses "default" if no name given)'
)


def parse_args() -> Namespace:
"""
Parse command-line arguments for Starlet Setup.

Returns:
Parsed arguments namespace
"""
config, config_path = load_config()

parser = argparse.ArgumentParser(
description="Starlet Setup - Quick setup script for CMake projects",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
Single Repository Mode:
%(prog)s https://github.com/username/repo.git
%(prog)s git@github.com:username/repo.git
%(prog)s username/repo
%(prog)s username/repo --ssh
%(prog)s username/repo --no-build
%(prog)s username/repo --build-dir build_name --build-type Release

Mono-repo Repository Mode:
%(prog)s username/repo --mono-repo
%(prog)s username/repo --mono-repo --ssh --mono-dir my_workspace
%(prog)s username/repo --repos user/lib1 user/lib2 user/lib3

Profile Repository Mode:
%(prog)s username/repo --profile
%(prog)s username/repo --profile myprofile

Profile Management:
%(prog)s --list-profiles
%(prog)s --profile-add myprofile user/lib1 user/lib2 user/lib3
%(prog)s --profile-remove myprofile

Config Mangement:
%(prog)s --init-config
%(prog)s --list-configs
%(prog)s --config-add myconfig
%(prog)s --config-add myconfig --ssh --no-build --build-type Release
%(prog)s --config-remove myconfig
"""
)

# Repository argument
parser.add_argument(
'repo',
nargs='?',
help='Repository name (username/repo) or full GitHub URL'
)
_add_common_args(parser, config)
_add_config_management_args(parser)
_add_profile_management_args(parser)
_add_build_args(parser, config)
_add_mono_repo_args(parser, config)

args = parser.parse_args()
args.config = config
args.config_path = config_path

if args.init_config or args.list_profiles or args.profile_add or args.profile_remove:
if args.init_config \
or args.list_configs or args.config_add or args.config_remove \
or args.list_profiles or args.profile_add or args.profile_remove:
return args

if not args.repo:
parser.error("Repository argument is required")

if args.profile or args.repos:
args.mono_repo = True

if args.repos and args.profile:
parser.error("Cannot use both --repos and --profile")
if args.repos or args.profile:
args.mono_repo = True

return args
Loading