-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): Add an initial code for the CLI option defined by the user (#…
…225)
- Loading branch information
1 parent
0e3f0ec
commit 1b1db90
Showing
13 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ jobs: | |
- linters.sh | ||
- tests.sh | ||
- virtual-envs.sh | ||
- cli.sh | ||
|
||
defaults: | ||
run: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Interface for the `python -m scicookie`.""" | ||
|
||
from scicookie.cli import app | ||
|
||
if __name__ == "__main__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Module with CLI functions.""" | ||
|
||
import argparse | ||
import json | ||
import os | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Module for functions and classes for systen logs.""" | ||
|
||
import os | ||
|
||
from enum import Enum | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Define functions for the interface with the user.""" | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/scicookie/{{cookiecutter.project_slug}}/{{cookiecutter.package_slug}}/cli.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
"""Module with CLI functions.""" | ||
|
||
{%- if cookiecutter.command_line_interface == "Argparse" %} | ||
|
||
import argparse | ||
|
||
from {{ cookiecutter.package_slug }} import __version__ | ||
|
||
|
||
class CustomHelpFormatter(argparse.RawTextHelpFormatter): | ||
"""Formatter for generating usage messages and argument help strings. | ||
Only the name of this class is considered a public API. All the methods | ||
provided by the class are considered an implementation detail. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
prog, | ||
indent_increment=2, | ||
max_help_position=4, | ||
width=None, | ||
**kwargs, | ||
): | ||
super().__init__( | ||
prog, | ||
indent_increment=indent_increment, | ||
max_help_position=max_help_position, | ||
width=width, | ||
**kwargs, | ||
) | ||
|
||
|
||
def get_args(): | ||
"""Return the arguments for the CLI.""" | ||
parser = argparse.ArgumentParser( | ||
prog="{{ cookiecutter.project_slug }}", | ||
description=("{{ cookiecutter.project_name }}"), | ||
epilog=( | ||
"If you have any problem, open an issue at: " | ||
"{{ cookiecutter.project_url }}" | ||
), | ||
add_help=True, | ||
formatter_class=CustomHelpFormatter, | ||
) | ||
parser.add_argument( | ||
"--version", | ||
action="store_true", | ||
help="Show the version of the installed {{ cookiecutter.project_name }} tool.", | ||
) | ||
|
||
return parser | ||
|
||
|
||
def show_version(): | ||
"""Show the version for the application.""" | ||
print(__version__) | ||
|
||
|
||
def app(): | ||
"""Run the application.""" | ||
args_parser = get_args() | ||
args = args_parser.parse_args() | ||
|
||
if args.version: | ||
return show_version() | ||
|
||
{%- elif cookiecutter.command_line_interface == "Click" %} | ||
|
||
import click | ||
|
||
from {{ cookiecutter.package_slug }} import __version__ | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"--version", | ||
is_flag=True, | ||
help="Show the version of the installed {{ cookiecutter.project_name }} tool.", | ||
) | ||
def app(version): | ||
"""Run the application.""" | ||
if version: | ||
return click.echo(__version__) | ||
click.echo("You can add more Click commands here.") | ||
|
||
{%- endif %} | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
SMOKE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
. ${SMOKE_DIR}/base.sh "command_line_interface=Argparse" | ||
. ${SMOKE_DIR}/base.sh "command_line_interface=Click" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Cookiecutter bake test.""" | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
|