Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit d3f5bb9

Browse files
author
Hendrik van Antwerpen
authored
Merge pull request #143 from github/small-init-fixes
Fixes to `init` command
2 parents 978a0da + 24a9d6e commit d3f5bb9

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

tree-sitter-stack-graphs/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### CLI
11+
12+
#### Changed
13+
14+
- The default values for the `init` commmand changed to match naming conventions.
15+
- After `init` read all user input, it presents an overview of selected settings and asks for user confirmation before creating any files.
16+
17+
### Fixed
18+
19+
- Several issues with content or location of files generated by `init` command.
20+
821
## v0.4.0 -- 2022-10-19
922

1023
Depend on `tree-sitter-graph` version 0.7.

tree-sitter-stack-graphs/src/bin/tree-sitter-stack-graphs/init.rs

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use anyhow::anyhow;
99
use clap::ValueHint;
10+
use dialoguer::Confirm;
1011
use dialoguer::{Input, Validator};
1112
use indoc::printdoc;
1213
use indoc::writedoc;
@@ -38,11 +39,47 @@ impl Command {
3839
pub fn run(&self) -> anyhow::Result<()> {
3940
self.check_project_dir()?;
4041
let config = ProjectSettings::read_from_console()?;
42+
43+
printdoc! {r##"
44+
Review project settings:
45+
46+
Project directory : {}
47+
Language name : {}
48+
Language identifier : {}
49+
Language file extension : {}
50+
Project package name : {}
51+
Project package version : {}
52+
Project author : {}
53+
Project license : {}
54+
Grammar dependency name : {}
55+
Grammar dependency version : {}
56+
57+
"##,
58+
self.project_path.display(),
59+
config.language_name,
60+
config.language_id,
61+
config.language_file_extension,
62+
config.project_npm_name,
63+
config.project_npm_version,
64+
config.project_author,
65+
config.project_license,
66+
config.grammar_npm_name,
67+
config.grammar_npm_version,
68+
};
69+
let confirm = Confirm::new()
70+
.with_prompt("Generate project")
71+
.default(true)
72+
.interact()?;
73+
if !confirm {
74+
println!("Project not created.")
75+
}
76+
4177
config.generate_files_into(&self.project_path)?;
4278
printdoc! {r#"
4379
44-
Project created! More information about the project can be found in README.md.
45-
"#
80+
Project created. See {} to get started!
81+
"#,
82+
self.project_path.join("README.md").display(),
4683
};
4784
Ok(())
4885
}
@@ -127,12 +164,12 @@ impl ProjectSettings {
127164

128165
printdoc! {r#"
129166
130-
Give the NPM package version for this project. Usually matches the version of the
131-
grammar being used.
167+
Give the NPM package version for this project.
132168
"#
133169
};
134170
let project_npm_version: String = Input::new()
135171
.with_prompt("Project NPM package version")
172+
.with_initial_text("0.1.0")
136173
.validate_with(regex_validator(&VALID_NPM_VERSION))
137174
.interact_text()?;
138175
println!();
@@ -175,14 +212,15 @@ impl ProjectSettings {
175212
176213
Give the NPM package version or dependency string for the {} dependency. The
177214
format can be any of:
178-
- MAJOR.MINOR.PATCH A regular version
215+
- MAJOR.MINOR.PATCH An NPM release version.
216+
Prefix with ~ to allow any patch version, for example: ~0.4.1
217+
Prefix with ^ to allow any minor version, for example: ^1.2.7
179218
- github:OWNER/REPOSITORY#COMMITISH A GitHub dependency, tagged to a branch, tag, or commit SHA
180219
"##,
181220
grammar_npm_name,
182221
};
183222
let grammar_npm_version: String = Input::new()
184223
.with_prompt("Grammar NPM package version")
185-
.with_initial_text(&project_npm_version)
186224
.interact_text()?;
187225
println!();
188226

@@ -282,10 +320,10 @@ impl ProjectSettings {
282320
self.language_name, self.grammar_npm_name,
283321
}?;
284322
if !self.project_author.is_empty() {
285-
writeln!(file, r#" "author": "{}""#, self.project_author)?;
323+
writeln!(file, r#" "author": "{}","#, self.project_author)?;
286324
}
287325
if !self.project_license.is_empty() {
288-
writeln!(file, r#" "license": "{}""#, self.project_license)?;
326+
writeln!(file, r#" "license": "{}","#, self.project_license)?;
289327
}
290328
writedoc! {file, r##"
291329
"keywords": [
@@ -294,7 +332,7 @@ impl ProjectSettings {
294332
"{}"
295333
],
296334
"devDependencies": {{
297-
"tree-sitter-stack-graphs": "{}",
335+
"tree-sitter-stack-graphs": "~{}",
298336
"{}": "{}"
299337
}},
300338
"scripts": {{
@@ -315,7 +353,7 @@ impl ProjectSettings {
315353
}
316354

317355
fn generate_cargo_toml(&self, project_path: &Path) -> anyhow::Result<()> {
318-
let mut file = File::create(project_path.join("bindings/rust/Cargo.toml"))?;
356+
let mut file = File::create(project_path.join("Cargo.toml"))?;
319357
writedoc! {file, r#"
320358
[package]
321359
name = "{}"
@@ -345,7 +383,11 @@ impl ProjectSettings {
345383
346384
[lib]
347385
path = "bindings/rust/lib.rs"
386+
387+
[dev-dependencies]
388+
tree-sitter-stack-graphs = "~{}"
348389
"#,
390+
TSSG_VERSION,
349391
}?;
350392
Ok(())
351393
}

0 commit comments

Comments
 (0)