Skip to content

Commit 6df9902

Browse files
committed
Make new interactive.
1 parent 4763058 commit 6df9902

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

hatch/commands/new.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
@click.command(context_settings=CONTEXT_SETTINGS,
1717
short_help='Creates a new Python project')
18-
@click.argument('name')
18+
@click.argument('name', nargs=-1, default=None)
1919
@click.option('-ne', '--no-env', is_flag=True,
2020
help=(
2121
'Disables the creation of a dedicated virtual env.'
@@ -44,9 +44,7 @@
4444
'within. Also, a `__main__.py` is created so it can be '
4545
'invoked via `python -m pkg_name`.'
4646
))
47-
@click.option('-l', '--licenses',
48-
help='Comma-separated list of licenses to use.')
49-
def new(name, no_env, pyname, pypath, env_name, basic, cli, licenses):
47+
def new(name, no_env, pyname, pypath, env_name, basic, cli):
5048
"""Creates a new Python project.
5149
5250
Values from your config file such as `name` and `pyversions` will be used
@@ -91,18 +89,27 @@ def new(name, no_env, pyname, pypath, env_name, basic, cli, licenses):
9189
if basic:
9290
settings['basic'] = True
9391

94-
if licenses:
95-
settings['licenses'] = licenses.split(',')
96-
9792
settings['cli'] = cli
9893

9994
origin = os.getcwd()
100-
d = os.path.join(origin, name)
95+
if name:
96+
settings['package_name'] = name[0]
97+
else:
98+
settings['package_name'] = click.prompt('project name')
99+
100+
d = os.path.join(origin, settings['package_name'])
101101

102102
if os.path.exists(d):
103103
echo_failure('Directory `{}` already exists.'.format(d))
104104
sys.exit(1)
105105

106+
settings['version'] = click.prompt('version', default='1.0.0')
107+
settings['description'] = click.prompt('description', default='')
108+
settings['author'] = click.prompt('author', default='')
109+
settings['email'] = click.prompt('author_email', default='')
110+
licenses = click.prompt('license', default='mit')
111+
settings['licenses'] = map(str.strip, licenses.split(','))
112+
106113
venvs = env_name.split('/') if env_name else []
107114
if (venvs or not no_env) and pyname:
108115
try:
@@ -118,8 +125,8 @@ def new(name, no_env, pyname, pypath, env_name, basic, cli, licenses):
118125

119126
os.makedirs(d)
120127
with chdir(d, cwd=origin):
121-
create_package(d, name, settings)
122-
echo_success('Created project `{}`'.format(name))
128+
create_package(d, settings)
129+
echo_success('Created project `{}`'.format(settings['package_name']))
123130

124131
if not no_env:
125132
venv_dir = os.path.join(d, 'venv')

0 commit comments

Comments
 (0)