fix: correct complete flag
This commit is contained in:
parent
ac60443a08
commit
bee822fe32
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
/my_project
|
82
README.md
82
README.md
|
@ -1 +1,83 @@
|
||||||
# pynit
|
# pynit
|
||||||
|
|
||||||
|
`pynit` speed up the process of creating a new python project. It can initialise the project with `git`,
|
||||||
|
a virtual environment (using the `venv` module) and creating a [basic folder structure](https://setuptools.pypa.io/en/latest/userguide/package_discovery.html) if wanted.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
Small CLI tool to initialize a python project
|
||||||
|
|
||||||
|
Usage: pynit [OPTIONS] <COMMAND>
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
new
|
||||||
|
init
|
||||||
|
help Print this message or the help of the given subcommand(s)
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-v, --verbose Output will be more verbose
|
||||||
|
-c, --complete Initialize with minimal fields for "pyproject.toml"
|
||||||
|
--git Initialize folder with a git repository
|
||||||
|
--venv <VENV> Initialize a new virtual environment with given name in initialized directory
|
||||||
|
--layout <LAYOUT> Define a layout for your project (https://setuptools.pypa.io/en/latest/userguide/package_discovery.html) [possible values: src, flat]
|
||||||
|
-h, --help Print help information
|
||||||
|
-V, --version Print version information
|
||||||
|
```
|
||||||
|
|
||||||
|
2 subcommands are available: `new` and `init`. Each of them have the same flags (defined globally).
|
||||||
|
|
||||||
|
### Global flags
|
||||||
|
|
||||||
|
#### --verbose
|
||||||
|
|
||||||
|
Adding this flag will make the `STDOUT` more verbose.
|
||||||
|
|
||||||
|
NOTE: the flag doesn't do anything currently as logging is not yet implemented.
|
||||||
|
|
||||||
|
#### -c/--complete
|
||||||
|
|
||||||
|
`--complete` allows you to control how much questions will be asked during the initialisation of the `pyproject.toml`. By default, only required fields will be asked: `build-sytem` section, `project.name` and `project.version`.
|
||||||
|
|
||||||
|
#### --git
|
||||||
|
|
||||||
|
Initialise a git repository
|
||||||
|
|
||||||
|
#### --venv
|
||||||
|
|
||||||
|
Add a virtual environment to your python project with a given `name`.
|
||||||
|
|
||||||
|
#### --layout
|
||||||
|
|
||||||
|
Add a default popular folder structure to your project.
|
||||||
|
Two options are available: `flat` and `src`.
|
||||||
|
|
||||||
|
For more information, check out [this setuptools section](https://setuptools.pypa.io/en/latest/userguide/package_discovery.html).
|
||||||
|
|
||||||
|
### new
|
||||||
|
|
||||||
|
`new` acts like `cargo new`. It take one argument which is the project name. Project name will be the folder name and used as default when asking questions to create a basic `pyproject.toml`.
|
||||||
|
|
||||||
|
The directory must NOT exist before creating the project.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ pynit --git --venv .env --layout flat new my_project
|
||||||
|
$ exa -a --tree --level=2 my_project
|
||||||
|
my_project
|
||||||
|
├── .env
|
||||||
|
│ ├── ...
|
||||||
|
├── .git
|
||||||
|
│ ├── ...
|
||||||
|
├── .gitignore
|
||||||
|
├── my_project
|
||||||
|
│ └── __init__.py
|
||||||
|
└── pyproject.toml
|
||||||
|
```
|
||||||
|
|
||||||
|
### init
|
||||||
|
|
||||||
|
Like `new`, `init` does the same thing. Except it'll initiase the current directory.
|
||||||
|
|
||||||
|
NOTE: if a `.gitignore` and/or a `pyproject.toml` is present, they'll be truncated.
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -2,7 +2,7 @@ use std::{
|
||||||
env,
|
env,
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::Command,
|
process::{Command, Stdio},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
@ -25,11 +25,11 @@ struct Args {
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
|
|
||||||
/// Initialize with minimal fields for "pyproject.toml"
|
/// Initialize with minimal fields for "pyproject.toml"
|
||||||
#[arg(short, long, default_value_t = true)]
|
#[arg(short, long)]
|
||||||
minimum: bool,
|
complete: bool,
|
||||||
|
|
||||||
/// Initialize folder with a git repository
|
/// Initialize folder with a git repository
|
||||||
#[arg(long, default_value_t = true)]
|
#[arg(long)]
|
||||||
git: bool,
|
git: bool,
|
||||||
|
|
||||||
/// Initialize a new virtual environment with given name in initialized directory
|
/// Initialize a new virtual environment with given name in initialized directory
|
||||||
|
@ -58,12 +58,12 @@ fn main() -> Result<()> {
|
||||||
fs::create_dir(&folder)?;
|
fs::create_dir(&folder)?;
|
||||||
let folder = folder.canonicalize()?;
|
let folder = folder.canonicalize()?;
|
||||||
|
|
||||||
initialize_folder(folder, args.minimum, args.layout, args.venv, args.git)?;
|
initialize_folder(folder, args.complete, args.layout, args.venv, args.git)?;
|
||||||
}
|
}
|
||||||
Subcommands::Init {} => {
|
Subcommands::Init {} => {
|
||||||
let folder = env::current_dir()?;
|
let folder = env::current_dir()?;
|
||||||
|
|
||||||
initialize_folder(folder, args.minimum, args.layout, args.venv, args.git)?;
|
initialize_folder(folder, args.complete, args.layout, args.venv, args.git)?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -72,13 +72,13 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
fn initialize_folder(
|
fn initialize_folder(
|
||||||
folder: PathBuf,
|
folder: PathBuf,
|
||||||
minimum: bool,
|
complete: bool,
|
||||||
layout: Option<Layout>,
|
layout: Option<Layout>,
|
||||||
venv: Option<String>,
|
venv: Option<String>,
|
||||||
git: bool,
|
git: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// todo: avoid clone and maybe find a better way
|
// todo: avoid clone and maybe find a better way
|
||||||
let mut pypro = Pyproject::new(folder.clone(), minimum);
|
let mut pypro = Pyproject::new(folder.clone(), complete);
|
||||||
|
|
||||||
pypro.ask_inputs()?;
|
pypro.ask_inputs()?;
|
||||||
let project_name = pypro.get_project_name();
|
let project_name = pypro.get_project_name();
|
||||||
|
@ -107,12 +107,14 @@ fn initialize_folder(
|
||||||
Command::new("python3")
|
Command::new("python3")
|
||||||
.args(&["-m", "venv", &venv])
|
.args(&["-m", "venv", &venv])
|
||||||
.current_dir(&folder)
|
.current_dir(&folder)
|
||||||
|
.stdout(Stdio::null())
|
||||||
.status()?;
|
.status()?;
|
||||||
}
|
}
|
||||||
if git {
|
if git {
|
||||||
Command::new("git")
|
Command::new("git")
|
||||||
.args(&["init"])
|
.args(&["init"])
|
||||||
.current_dir(&folder)
|
.current_dir(&folder)
|
||||||
|
.stdout(Stdio::null())
|
||||||
.status()?;
|
.status()?;
|
||||||
fs::write(
|
fs::write(
|
||||||
folder.join(".gitignore"),
|
folder.join(".gitignore"),
|
||||||
|
|
|
@ -13,16 +13,16 @@ pub struct Pyproject {
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
folder: PathBuf,
|
folder: PathBuf,
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
minimum: bool,
|
complete: bool,
|
||||||
pub build_system: BuildSystem,
|
pub build_system: BuildSystem,
|
||||||
pub project: Project,
|
pub project: Project,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pyproject {
|
impl Pyproject {
|
||||||
pub fn new(folder: PathBuf, minimum: bool) -> Self {
|
pub fn new(folder: PathBuf, complete: bool) -> Self {
|
||||||
Pyproject {
|
Pyproject {
|
||||||
folder,
|
folder,
|
||||||
minimum,
|
complete,
|
||||||
build_system: BuildSystem::default(),
|
build_system: BuildSystem::default(),
|
||||||
project: Project::default(),
|
project: Project::default(),
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ impl Pyproject {
|
||||||
.default("0.1.0".to_string())
|
.default("0.1.0".to_string())
|
||||||
.interact_text()?;
|
.interact_text()?;
|
||||||
|
|
||||||
if !self.minimum {
|
if self.complete {
|
||||||
self.project.description = Input::with_theme(&theme)
|
self.project.description = Input::with_theme(&theme)
|
||||||
.with_prompt("description")
|
.with_prompt("description")
|
||||||
.allow_empty(true)
|
.allow_empty(true)
|
||||||
|
|
Loading…
Reference in New Issue