Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified initialization #11

Merged
merged 1 commit into from
Feb 29, 2024
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
44 changes: 13 additions & 31 deletions pulse/init/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
from pulse.project.initialize import initialize, TYPE_GAMEMODE, TYPE_LIBRARY

@click.command
@click.option('-g', '--gamemode', is_flag=True, help='Initialize a game mode package')
@click.option('-l', '--library', is_flag=True, help='Initialize a library package')
def init(gamemode: bool, library: bool) -> None:
def init() -> None:
"""
Initialize a new Pulse project.

Expand Down Expand Up @@ -36,32 +34,16 @@ def init(gamemode: bool, library: bool) -> None:
data = config.load()
default_name = data['last_username']

if library and gamemode:
click.echo('Can\'t use both flags. Either initialize library or gamemode.')
elif gamemode:
name = click.prompt(f'Your name for publishing? Should be github username', default=default_name if default_name != 'NO_NAME_BRO' else None)
data['last_username'] = name
project = click.prompt('Enter the name for your gamemode. It will be used as a project name')
repo = click.prompt('Enter the name for your github repository. Could be left blank if you won\'t publish it')

initialize(project, TYPE_GAMEMODE, name, repo)
config.write(data, 'w')
elif library:
name = click.prompt(f'Your name for publishing? Should be github username', default=default_name if default_name != 'NO_NAME_BRO' else None)
data['last_username'] = name
project = click.prompt('Enter the name for your project. It will be used as a project name')
repo = click.prompt('Enter the name for your github repository. Could be left blank if you won\'t publish it')
create = click.prompt('Enter whether to initialize github repo (Input (y)es or (n)o?)', default='y')
name = click.prompt(f'Your name for publishing? Should be github username', default=default_name if default_name != 'NO_NAME_BRO' else None)
data['last_username'] = name

initialize(project, TYPE_LIBRARY, name, repo)
config.write(data, 'w')
if create == 'y' or create == 'yes':
create_repository(name, repo, data['token'])
elif create == 'n' or create == 'no':
pass
else:
click.echo('Since you input nonsense, we assume yes.')
create_repository(name, repo, data['token'])

else:
click.echo('Invalid syntax. Use pulse --help')
project = click.prompt('Enter the name for your project. It will be used as a project name')
repo = click.prompt('Enter the name for your github repository.')
create = click.confirm('Initialize the repo?', default=True)

initialize(project, name, repo)
config.write(data, 'w')

if create:
click.secho('Repository has been created successfully', fg='green')
create_repository(name, repo, data['token'])
Empty file.
8 changes: 2 additions & 6 deletions pulse/project/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
`pulse install ^publisher^/^package_name^`
"""

def initialize(name: str, type: int, publisher: str, repo_name: str, entry: str = 'main.pwn') -> None:
def initialize(name: str, publisher: str, repo_name: str, entry: str = 'main.pwn') -> None:
"""
Initialize a new Project instance.

Expand All @@ -84,14 +84,10 @@ def initialize(name: str, type: int, publisher: str, repo_name: str, entry: str
type (int): The type of the project (1 for gamemode, 2 for library).
publisher (str): The publisher or creator of the project.
repo_name (str): The name of the repository.

Raises:
ValueError: If an invalid project type is provided.
"""

project_table = {
'name': name,
'type': 'gamemode' if type == TYPE_GAMEMODE else 'library',
'publisher': publisher,
'repo': repo_name
}
Expand All @@ -114,5 +110,5 @@ def initialize(name: str, type: int, publisher: str, repo_name: str, entry: str
with open(md_file, 'w') as md:
md.write(markdown_content.replace('^package_name^', f'{name}')
.replace('^publisher^', f'{publisher}')
.replace('in_part_1', install_part_gamemode if type == TYPE_GAMEMODE else install_part_library))
.replace('in_part_1', install_part_library))