Skip to content

Adds command "cookiecutter installed" to list installed (locally available) templates.#916

Closed
mikeckennedy wants to merge 4 commits intocookiecutter:masterfrom
mikeckennedy:mikeckennedy/installed_feature
Closed

Adds command "cookiecutter installed" to list installed (locally available) templates.#916
mikeckennedy wants to merge 4 commits intocookiecutter:masterfrom
mikeckennedy:mikeckennedy/installed_feature

Conversation

@mikeckennedy
Copy link
Copy Markdown
Contributor

Adds new command: cookiecutter installed

This lists locally available templates, for example:

user$ cookiecutter installed
7 installed templates: 
 * cookiecutter-bottle
 * cookiecutter-pyramid-talk-python-starter
 * cookiecutter-sublime-text-3-plugin
 * cookiecutter-template
 * puppet-openstack-cookiecutter
 * pyramid-cookiecutter-starter
 * python-macon-template

I was not able to integrate it into click without breaking the existing functionality. Someone who knows click better than me please adjust this if possible.

I’d like to see just cookiecutter —installed as the command (so it would be listed in help output) but I only get a missing template error and all attempts to add the command as an option met with my lack of experience with click.

This lists locally available templates, for example:

```
user$ cookiecutter installed
7 installed templates:
 * cookiecutter-bottle
 * cookiecutter-pyramid-talk-python-starter
 * cookiecutter-sublime-text-3-plugin
 * cookiecutter-template
 * puppet-openstack-cookiecutter
 * pyramid-cookiecutter-starter
 * python-macon-template
```

I was not able to integrate it into click without breaking the existing functionality. Someone who knows click better than me please adjust this if possible.

I’d like to see just `cookiecutter —installed` as the command (and it would need to list in help) but I only get missing template and all attempts to add it as an option met with my lack of exepreience with click.
@hackebrot
Copy link
Copy Markdown
Member

Hey @mikeckennedy! 👋

Thanks for the PR. I'll have a look into the CLI implementation.

What does the -27 exit code mean and is that platform agnostic?

@hackebrot hackebrot added the enhancement This issue/PR relates to a feature request. label May 7, 2017
@mikeckennedy
Copy link
Copy Markdown
Contributor Author

Thanks @hackebrot that would be great to see this feature.

-27 is just a number to be unique. Feel free to use any failure code that makes the most sense.

if template == u'help':
click.echo(click.get_current_context().get_help())
sys.exit(0)
if template == u'installed' or template == u'i':
Copy link
Copy Markdown

@theodesp theodesp Aug 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better if you name it --list-installed as its is more accurate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great to me. I'm open to basically any name for the command. But it's a real pain to hunt down the template names over and over. Once you have them downloaded it would be nice to use it as a list of what you've used before.

if not os.path.exists(cookiecutter_folder):
click.echo('Error: Cannot list installed templates. ' +
'Folder does not exist: {}'.format(cookiecutter_folder))
sys.exit(-27)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you just return sys.exit(-1) it's more ordinary that way

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simply wanted a different code than other errors so things scripting cookiecutter can use that as a signal for why / how something failed. If everywhere you return -1 how do you know what went wrong?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, But I think this is a separate consideration to handle as in the project for now exit returns with -1 or 0. Maybe log a ticket to have this extra functionality.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. For the sake of this PR I'm happy to make it -1. But this could be something to consider in general for cookiecutter.

@theodesp
Copy link
Copy Markdown

theodesp commented Aug 9, 2017

@mikeckennedy It looks like you need to add a few more tests to maintain the coverage 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This issue/PR relates to a feature request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants