@repokit/core 1.0.5 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/externals/types.ts +1 -0
- package/{install.sh → installation/install.sh} +1 -1
- package/internals/configuration/configuration.rs +2 -1
- package/internals/executables/internal_executable_definition.rs +35 -3
- package/internals/external_commands/external_commands.rs +2 -2
- package/internals/internal_commands/help.rs +27 -22
- package/internals/internal_commands/list_commands.rs +9 -7
- package/internals/internal_commands/list_owners.rs +6 -4
- package/internals/internal_commands/locate_command.rs +6 -4
- package/internals/internal_commands/onboarder.rs +6 -4
- package/internals/internal_commands/register_command.rs +9 -6
- package/internals/internal_commands/search_commands.rs +19 -12
- package/internals/internal_commands/typescript_command.rs +7 -4
- package/internals/internal_commands/upgrade_repokit.rs +6 -4
- package/internals/internal_filesystem/internal_filesystem.rs +28 -17
- package/internals/logger/logger.rs +8 -0
- package/internals/main.rs +1 -1
- package/internals/repokit/interfaces.rs +10 -7
- package/internals/repokit/repokit.rs +5 -4
- package/package.json +5 -3
package/externals/types.ts
CHANGED
|
@@ -12,7 +12,8 @@ impl Configuration {
|
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
Configuration::welcome();
|
|
15
|
-
let template_path =
|
|
15
|
+
let template_path =
|
|
16
|
+
InternalFileSystem::new(root).resolve_template("configuration_template.ts");
|
|
16
17
|
let mut source = File::open(template_path).expect("Template");
|
|
17
18
|
let mut target = File::create(path_buf).expect("creating");
|
|
18
19
|
io::copy(&mut source, &mut target).expect("writing");
|
|
@@ -2,7 +2,39 @@ use std::collections::HashMap;
|
|
|
2
2
|
|
|
3
3
|
#[derive(Clone)]
|
|
4
4
|
pub struct InternalExecutableDefinition {
|
|
5
|
-
pub name:
|
|
6
|
-
pub description:
|
|
7
|
-
pub args: HashMap
|
|
5
|
+
pub name: String,
|
|
6
|
+
pub description: String,
|
|
7
|
+
pub args: Option<HashMap<String, String>>,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
pub struct InternalExecutableDefinitionInput<'a, const N: usize> {
|
|
11
|
+
pub name: &'a str,
|
|
12
|
+
pub description: &'a str,
|
|
13
|
+
pub args: [(&'a str, &'a str); N],
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
impl InternalExecutableDefinition {
|
|
17
|
+
pub fn define<'a, const N: usize>(
|
|
18
|
+
definition: InternalExecutableDefinitionInput<N>,
|
|
19
|
+
) -> InternalExecutableDefinition {
|
|
20
|
+
let InternalExecutableDefinitionInput {
|
|
21
|
+
name,
|
|
22
|
+
description,
|
|
23
|
+
args,
|
|
24
|
+
} = definition;
|
|
25
|
+
InternalExecutableDefinition {
|
|
26
|
+
name: String::from(name),
|
|
27
|
+
description: String::from(description),
|
|
28
|
+
args: InternalExecutableDefinition::args(args),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pub fn args<const N: usize>(tuples: [(&str, &str); N]) -> Option<HashMap<String, String>> {
|
|
33
|
+
if tuples.is_empty() {
|
|
34
|
+
return None;
|
|
35
|
+
}
|
|
36
|
+
Some(HashMap::from(tuples.map(|(key, value)| {
|
|
37
|
+
(String::from(key), String::from(value))
|
|
38
|
+
})))
|
|
39
|
+
}
|
|
8
40
|
}
|
|
@@ -64,7 +64,7 @@ impl ExternalCommands {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
pool.pool.shutdown_background();
|
|
67
|
-
TypescriptCommand::new(self.root
|
|
67
|
+
TypescriptCommand::new(&self.root).parse_commands(paths)
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
fn read(path: &Path) -> bool {
|
|
@@ -72,7 +72,7 @@ impl ExternalCommands {
|
|
|
72
72
|
let reader: BufReader<File> = BufReader::new(file);
|
|
73
73
|
for line_result in reader.lines() {
|
|
74
74
|
let line: String = line_result.expect("line");
|
|
75
|
-
if line.
|
|
75
|
+
if line.ends_with("\"@repokit/core\";") {
|
|
76
76
|
return true;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -3,19 +3,19 @@ use std::collections::HashMap;
|
|
|
3
3
|
use alphanumeric_sort::{sort_slice_by_str_key, sort_str_slice};
|
|
4
4
|
|
|
5
5
|
use crate::{
|
|
6
|
-
repokit::interfaces::{Command, RepoKitCommand, ParsedCommand},
|
|
7
6
|
executables::{
|
|
8
7
|
intenal_executable::InternalExecutable,
|
|
9
8
|
internal_executable_definition::InternalExecutableDefinition,
|
|
10
9
|
},
|
|
11
10
|
logger::logger::Logger,
|
|
11
|
+
repokit::interfaces::{CommandDefinition, RepoKitCommand, RootCommand},
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
pub struct Help;
|
|
15
15
|
|
|
16
16
|
impl Help {
|
|
17
17
|
pub fn list_all(
|
|
18
|
-
root_commands: &HashMap<String,
|
|
18
|
+
root_commands: &HashMap<String, CommandDefinition>,
|
|
19
19
|
internals: &HashMap<String, Box<dyn InternalExecutable>>,
|
|
20
20
|
externals: &HashMap<String, RepoKitCommand>,
|
|
21
21
|
) {
|
|
@@ -28,29 +28,31 @@ impl Help {
|
|
|
28
28
|
println!(
|
|
29
29
|
"{}{} {}",
|
|
30
30
|
Logger::indent(Some(3)),
|
|
31
|
-
Logger::
|
|
32
|
-
Logger::gray(command.description),
|
|
31
|
+
Logger::blue(&command.name),
|
|
32
|
+
Logger::gray(&command.description),
|
|
33
33
|
);
|
|
34
|
-
Help::
|
|
34
|
+
Help::log_args(&command.args, None);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
pub fn log_root_command(command: &
|
|
37
|
+
pub fn log_root_command(command: &RootCommand) {
|
|
38
38
|
println!(
|
|
39
39
|
"{}{} {}",
|
|
40
40
|
Logger::indent(Some(3)),
|
|
41
41
|
Logger::blue(&command.name),
|
|
42
42
|
Logger::gray(&command.description),
|
|
43
43
|
);
|
|
44
|
+
Help::log_args(&command.args, None)
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
pub fn log_external_command(command: &RepoKitCommand) {
|
|
47
48
|
println!(
|
|
48
49
|
"{}{} {}",
|
|
49
50
|
Logger::indent(Some(3)),
|
|
50
|
-
Logger::
|
|
51
|
+
Logger::blue(&command.name),
|
|
51
52
|
Logger::gray(&command.description),
|
|
52
53
|
);
|
|
53
|
-
|
|
54
|
+
println!();
|
|
55
|
+
Help::log_external_subcommands(&command.commands, 6);
|
|
54
56
|
if !command.owner.is_empty() {
|
|
55
57
|
println!(
|
|
56
58
|
"\n{}{}{}",
|
|
@@ -61,14 +63,15 @@ impl Help {
|
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
pub fn
|
|
66
|
+
pub fn log_external_subcommands(map: &HashMap<String, CommandDefinition>, indentation: i32) {
|
|
65
67
|
for (name, command) in map {
|
|
66
68
|
println!(
|
|
67
69
|
"{}{}{}",
|
|
68
|
-
Logger::indent(indentation),
|
|
69
|
-
Logger::
|
|
70
|
+
Logger::indent(Some(indentation)),
|
|
71
|
+
Logger::lime(format!("{}: ", name).as_str()),
|
|
70
72
|
Logger::gray(&command.description),
|
|
71
73
|
);
|
|
74
|
+
Help::log_args(&command.args, Some(indentation + 3));
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
|
|
@@ -84,7 +87,7 @@ impl Help {
|
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
pub fn log_root_commands(root_commands: &HashMap<String,
|
|
90
|
+
pub fn log_root_commands(root_commands: &HashMap<String, CommandDefinition>) {
|
|
88
91
|
if root_commands.is_empty() {
|
|
89
92
|
return;
|
|
90
93
|
}
|
|
@@ -110,14 +113,16 @@ impl Help {
|
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
fn
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
fn log_args(map: &Option<HashMap<String, String>>, indentation: Option<i32>) {
|
|
117
|
+
if let Some(args) = map {
|
|
118
|
+
for (name, description) in args {
|
|
119
|
+
println!(
|
|
120
|
+
"{}{}{}",
|
|
121
|
+
Logger::indent(Some(indentation.unwrap_or(6))),
|
|
122
|
+
Logger::green(name.as_str()),
|
|
123
|
+
Logger::gray(format!(": {}", description).as_str()),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
121
126
|
}
|
|
122
127
|
}
|
|
123
128
|
|
|
@@ -135,12 +140,12 @@ impl Help {
|
|
|
135
140
|
vector
|
|
136
141
|
}
|
|
137
142
|
|
|
138
|
-
fn sort_root_commands(commands: &HashMap<String,
|
|
143
|
+
fn sort_root_commands(commands: &HashMap<String, CommandDefinition>) -> Vec<RootCommand> {
|
|
139
144
|
let mut vector: Vec<&String> = (commands).keys().collect();
|
|
140
145
|
sort_str_slice(&mut vector);
|
|
141
146
|
vector
|
|
142
147
|
.iter()
|
|
143
|
-
.map(|&name|
|
|
148
|
+
.map(|&name| RootCommand::from(name, commands.get(name).expect("known keys only")))
|
|
144
149
|
.collect()
|
|
145
150
|
}
|
|
146
151
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
use std::collections::HashMap;
|
|
2
2
|
|
|
3
3
|
use crate::{
|
|
4
|
-
repokit::interfaces::{RepoKitCommand, RepoKitConfig},
|
|
5
4
|
executables::{
|
|
6
5
|
intenal_executable::InternalExecutable,
|
|
7
|
-
internal_executable_definition::
|
|
6
|
+
internal_executable_definition::{
|
|
7
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
8
|
+
},
|
|
8
9
|
},
|
|
9
10
|
internal_commands::help::Help,
|
|
10
11
|
logger::logger::Logger,
|
|
12
|
+
repokit::interfaces::{RepoKitCommand, RepoKitConfig},
|
|
11
13
|
validations::command_validations::CommandValidations,
|
|
12
14
|
};
|
|
13
15
|
|
|
@@ -24,18 +26,18 @@ impl ListCommands {
|
|
|
24
26
|
ListCommands {
|
|
25
27
|
root,
|
|
26
28
|
configuration,
|
|
27
|
-
definition: InternalExecutableDefinition {
|
|
29
|
+
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
28
30
|
name: "list",
|
|
29
31
|
description: "List commands based on their scope of definition",
|
|
30
|
-
args:
|
|
32
|
+
args: [(
|
|
31
33
|
"<scope>",
|
|
32
34
|
format!(
|
|
33
35
|
"The scope of the commands you wish to list. Specify one of {}",
|
|
34
36
|
Logger::blue(SCOPES.join(" | ").as_str())
|
|
35
37
|
)
|
|
36
|
-
.
|
|
37
|
-
)]
|
|
38
|
-
},
|
|
38
|
+
.as_str(),
|
|
39
|
+
)],
|
|
40
|
+
}),
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -5,7 +5,9 @@ use alphanumeric_sort::sort_str_slice;
|
|
|
5
5
|
use crate::{
|
|
6
6
|
executables::{
|
|
7
7
|
intenal_executable::InternalExecutable,
|
|
8
|
-
internal_executable_definition::
|
|
8
|
+
internal_executable_definition::{
|
|
9
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
10
|
+
},
|
|
9
11
|
},
|
|
10
12
|
internal_commands::help::Help,
|
|
11
13
|
logger::logger::Logger,
|
|
@@ -24,11 +26,11 @@ impl ListOwners {
|
|
|
24
26
|
ListOwners {
|
|
25
27
|
root,
|
|
26
28
|
configuration,
|
|
27
|
-
definition: InternalExecutableDefinition {
|
|
29
|
+
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
28
30
|
name: "owners",
|
|
29
31
|
description: "Lists all registered command owners",
|
|
30
|
-
args:
|
|
31
|
-
},
|
|
32
|
+
args: [],
|
|
33
|
+
}),
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -4,7 +4,9 @@ use std::{collections::HashMap, process::exit};
|
|
|
4
4
|
use crate::{
|
|
5
5
|
executables::{
|
|
6
6
|
intenal_executable::InternalExecutable,
|
|
7
|
-
internal_executable_definition::
|
|
7
|
+
internal_executable_definition::{
|
|
8
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
9
|
+
},
|
|
8
10
|
},
|
|
9
11
|
external_commands::external_commands::ExternalCommands,
|
|
10
12
|
internal_commands::help::Help,
|
|
@@ -23,11 +25,11 @@ impl LocateCommand {
|
|
|
23
25
|
LocateCommand {
|
|
24
26
|
root,
|
|
25
27
|
configuration,
|
|
26
|
-
definition: InternalExecutableDefinition {
|
|
28
|
+
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
27
29
|
name: "locate",
|
|
28
30
|
description: "Locates command definitions",
|
|
29
|
-
args:
|
|
30
|
-
},
|
|
31
|
+
args: [("<name>", "The name of a registered command")],
|
|
32
|
+
}),
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -3,7 +3,9 @@ use std::collections::HashMap;
|
|
|
3
3
|
use crate::{
|
|
4
4
|
executables::{
|
|
5
5
|
intenal_executable::InternalExecutable,
|
|
6
|
-
internal_executable_definition::
|
|
6
|
+
internal_executable_definition::{
|
|
7
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
8
|
+
},
|
|
7
9
|
},
|
|
8
10
|
internal_commands::help::Help,
|
|
9
11
|
logger::logger::Logger,
|
|
@@ -21,11 +23,11 @@ impl Onboarder {
|
|
|
21
23
|
Onboarder {
|
|
22
24
|
root,
|
|
23
25
|
configuration,
|
|
24
|
-
definition: InternalExecutableDefinition {
|
|
26
|
+
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
25
27
|
name: "onboard",
|
|
26
28
|
description: "Onboarding instructions for first time users",
|
|
27
|
-
args:
|
|
28
|
-
},
|
|
29
|
+
args: [],
|
|
30
|
+
}),
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -10,7 +10,9 @@ use std::{
|
|
|
10
10
|
use crate::{
|
|
11
11
|
executables::{
|
|
12
12
|
intenal_executable::InternalExecutable,
|
|
13
|
-
internal_executable_definition::
|
|
13
|
+
internal_executable_definition::{
|
|
14
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
15
|
+
},
|
|
14
16
|
},
|
|
15
17
|
internal_commands::help::Help,
|
|
16
18
|
internal_filesystem::internal_filesystem::InternalFileSystem,
|
|
@@ -29,14 +31,14 @@ impl RegisterCommand {
|
|
|
29
31
|
RegisterCommand {
|
|
30
32
|
root,
|
|
31
33
|
configuration,
|
|
32
|
-
definition: InternalExecutableDefinition {
|
|
34
|
+
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
33
35
|
name: "register",
|
|
34
36
|
description: "Creates new Repokit commands",
|
|
35
|
-
args:
|
|
37
|
+
args: [(
|
|
36
38
|
"<path>",
|
|
37
39
|
"A relative path to your preferred command location",
|
|
38
|
-
)]
|
|
39
|
-
},
|
|
40
|
+
)],
|
|
41
|
+
}),
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
|
|
@@ -91,7 +93,8 @@ impl InternalExecutable for RegisterCommand {
|
|
|
91
93
|
fn run(&self, args: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
92
94
|
Logger::info("Registering a new command");
|
|
93
95
|
let command_path = self.validate_path(args);
|
|
94
|
-
let template_path =
|
|
96
|
+
let template_path =
|
|
97
|
+
InternalFileSystem::new(&self.root).resolve_template("command_template.ts");
|
|
95
98
|
let mut source = File::open(template_path).expect("Template");
|
|
96
99
|
let mut target = File::create(&command_path).expect("creating");
|
|
97
100
|
io::copy(&mut source, &mut target).expect("writing");
|
|
@@ -2,13 +2,15 @@ use alphanumeric_sort::sort_slice_by_str_key;
|
|
|
2
2
|
use std::collections::HashMap;
|
|
3
3
|
|
|
4
4
|
use crate::{
|
|
5
|
-
repokit::interfaces::{Command, RepoKitCommand, RepoKitConfig},
|
|
6
5
|
executables::{
|
|
7
6
|
intenal_executable::InternalExecutable,
|
|
8
|
-
internal_executable_definition::
|
|
7
|
+
internal_executable_definition::{
|
|
8
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
9
|
+
},
|
|
9
10
|
},
|
|
10
11
|
internal_commands::help::Help,
|
|
11
12
|
logger::logger::Logger,
|
|
13
|
+
repokit::interfaces::{CommandDefinition, RepoKitCommand, RepoKitConfig},
|
|
12
14
|
validations::command_validations::CommandValidations,
|
|
13
15
|
};
|
|
14
16
|
|
|
@@ -23,14 +25,14 @@ impl SearchCommands {
|
|
|
23
25
|
SearchCommands {
|
|
24
26
|
root,
|
|
25
27
|
configuration,
|
|
26
|
-
definition: InternalExecutableDefinition {
|
|
28
|
+
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
27
29
|
name: "search",
|
|
28
30
|
description: "Retrieve commands that match any search query",
|
|
29
|
-
args:
|
|
31
|
+
args: [(
|
|
30
32
|
"<query>",
|
|
31
33
|
"A search string to match against command names, descriptions, arguments, or owner",
|
|
32
|
-
)]
|
|
33
|
-
},
|
|
34
|
+
)],
|
|
35
|
+
}),
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -42,11 +44,16 @@ impl SearchCommands {
|
|
|
42
44
|
if config.description.to_lowercase().contains(query) {
|
|
43
45
|
return true;
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
if let Some(args) = &config.args {
|
|
48
|
+
for (arg, description) in args {
|
|
49
|
+
if arg.to_lowercase().contains(query)
|
|
50
|
+
|| description.to_lowercase().contains(query)
|
|
51
|
+
{
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
48
54
|
}
|
|
49
55
|
}
|
|
56
|
+
|
|
50
57
|
false
|
|
51
58
|
}
|
|
52
59
|
|
|
@@ -76,7 +83,7 @@ impl SearchCommands {
|
|
|
76
83
|
false
|
|
77
84
|
}
|
|
78
85
|
|
|
79
|
-
fn search_command(&self, query: &str, command: &
|
|
86
|
+
fn search_command(&self, query: &str, command: &CommandDefinition) -> bool {
|
|
80
87
|
if command.command.to_lowercase().contains(query)
|
|
81
88
|
|| command.description.to_lowercase().contains(query)
|
|
82
89
|
{
|
|
@@ -85,7 +92,7 @@ impl SearchCommands {
|
|
|
85
92
|
false
|
|
86
93
|
}
|
|
87
94
|
|
|
88
|
-
fn log_root_results(&self, root_results: &HashMap<String,
|
|
95
|
+
fn log_root_results(&self, root_results: &HashMap<String, CommandDefinition>) {
|
|
89
96
|
let total = root_results.len();
|
|
90
97
|
let plural_appendage = if total == 1 { "" } else { "s" };
|
|
91
98
|
if !root_results.is_empty() {
|
|
@@ -153,7 +160,7 @@ impl InternalExecutable for SearchCommands {
|
|
|
153
160
|
let query = args.join(" ").to_lowercase();
|
|
154
161
|
let externals = CommandValidations::new(self.root.clone(), self.configuration.clone())
|
|
155
162
|
.collect_and_validate_externals();
|
|
156
|
-
let mut root_results: HashMap<String,
|
|
163
|
+
let mut root_results: HashMap<String, CommandDefinition> = HashMap::new();
|
|
157
164
|
let mut internal_results: HashMap<String, &Box<dyn InternalExecutable>> = HashMap::new();
|
|
158
165
|
let mut external_results: HashMap<String, RepoKitCommand> = HashMap::new();
|
|
159
166
|
for (command, script) in &self.configuration.commands {
|
|
@@ -14,12 +14,15 @@ pub struct TypescriptCommand {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
impl TypescriptCommand {
|
|
17
|
-
pub fn new(root:
|
|
18
|
-
TypescriptCommand {
|
|
17
|
+
pub fn new(root: &str) -> TypescriptCommand {
|
|
18
|
+
TypescriptCommand {
|
|
19
|
+
root: root.to_string(),
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
pub fn parse_configuration(&self) -> RepoKitConfig {
|
|
22
|
-
let executable =
|
|
24
|
+
let executable =
|
|
25
|
+
InternalFileSystem::new(&self.root).resolve_command("parse_configuration.ts");
|
|
23
26
|
let stdout = self.execute(format!("{executable} --root {}", &self.root).as_str());
|
|
24
27
|
if stdout.is_empty() {
|
|
25
28
|
Configuration::create(&self.root);
|
|
@@ -31,7 +34,7 @@ impl TypescriptCommand {
|
|
|
31
34
|
|
|
32
35
|
pub fn parse_commands(&self, path_list: Vec<String>) -> Vec<RepoKitCommand> {
|
|
33
36
|
let paths = path_list.join(",");
|
|
34
|
-
let executable = InternalFileSystem::resolve_command("parse_commands.ts");
|
|
37
|
+
let executable = InternalFileSystem::new(&self.root).resolve_command("parse_commands.ts");
|
|
35
38
|
let stdout =
|
|
36
39
|
self.execute(format!("{executable} --paths {paths} --root {}", self.root).as_str());
|
|
37
40
|
let commands: Vec<RepoKitCommand> = serde_json::from_str(&stdout).expect("parse");
|
|
@@ -4,7 +4,9 @@ use std::{collections::HashMap, path::Path, process::exit};
|
|
|
4
4
|
use crate::{
|
|
5
5
|
executables::{
|
|
6
6
|
intenal_executable::InternalExecutable,
|
|
7
|
-
internal_executable_definition::
|
|
7
|
+
internal_executable_definition::{
|
|
8
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
9
|
+
},
|
|
8
10
|
},
|
|
9
11
|
executor::executor::Executor,
|
|
10
12
|
internal_commands::help::Help,
|
|
@@ -23,11 +25,11 @@ impl UpgradeRepoKit {
|
|
|
23
25
|
UpgradeRepoKit {
|
|
24
26
|
root,
|
|
25
27
|
configuration,
|
|
26
|
-
definition: InternalExecutableDefinition {
|
|
28
|
+
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
27
29
|
name: "upgrade",
|
|
28
30
|
description: "Upgrades your installation of repokit to the latest stable version",
|
|
29
|
-
args:
|
|
30
|
-
},
|
|
31
|
+
args: [],
|
|
32
|
+
}),
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -1,36 +1,47 @@
|
|
|
1
1
|
use normalize_path::NormalizePath;
|
|
2
2
|
use std::path::{Path, PathBuf};
|
|
3
3
|
|
|
4
|
-
pub struct InternalFileSystem
|
|
4
|
+
pub struct InternalFileSystem {
|
|
5
|
+
root: String,
|
|
6
|
+
}
|
|
5
7
|
|
|
6
8
|
impl InternalFileSystem {
|
|
7
|
-
pub fn
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
pub fn new(root: &str) -> InternalFileSystem {
|
|
10
|
+
InternalFileSystem {
|
|
11
|
+
root: root.to_string(),
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
pub fn absolute(&self, segment: &str) -> PathBuf {
|
|
16
|
+
let path = Path::new(&self.root);
|
|
10
17
|
path.join(segment).normalize()
|
|
11
18
|
}
|
|
12
19
|
|
|
13
|
-
pub fn resolve_command(file_name: &str) -> String {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
pub fn resolve_command(&self, file_name: &str) -> String {
|
|
21
|
+
self.path_buf_to_str(self.commands_directory().join(file_name))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pub fn resolve_template(&self, file_name: &str) -> String {
|
|
25
|
+
self.path_buf_to_str(self.templates_directory().join(file_name))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fn commands_directory(&self) -> PathBuf {
|
|
29
|
+
self.absolute(format!("{}/commands", self.package_directory()).as_str())
|
|
17
30
|
}
|
|
18
31
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
InternalFileSystem::templates_directory().join(file_name),
|
|
22
|
-
)
|
|
32
|
+
fn templates_directory(&self) -> PathBuf {
|
|
33
|
+
self.absolute(format!("{}/templates", self.package_directory()).as_str())
|
|
23
34
|
}
|
|
24
35
|
|
|
25
|
-
fn
|
|
26
|
-
|
|
36
|
+
fn package_directory(&self) -> String {
|
|
37
|
+
format!("./node_modules/{}/externals", self.package_name())
|
|
27
38
|
}
|
|
28
39
|
|
|
29
|
-
fn
|
|
30
|
-
|
|
40
|
+
fn package_name(&self) -> String {
|
|
41
|
+
"@repokit/core".to_string()
|
|
31
42
|
}
|
|
32
43
|
|
|
33
|
-
fn path_buf_to_str(buffer: PathBuf) -> String {
|
|
44
|
+
fn path_buf_to_str(&self, buffer: PathBuf) -> String {
|
|
34
45
|
buffer
|
|
35
46
|
.into_os_string()
|
|
36
47
|
.into_string()
|
|
@@ -84,6 +84,14 @@ impl Logger {
|
|
|
84
84
|
})
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
pub fn lime(message: &str) -> ColoredString {
|
|
88
|
+
message.custom_color(CustomColor {
|
|
89
|
+
r: 175,
|
|
90
|
+
g: 247,
|
|
91
|
+
b: 7,
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
87
95
|
fn info_prefix() -> ColoredString {
|
|
88
96
|
format!("{}: ", *REGISTERED_NAME.lock().unwrap())
|
|
89
97
|
.bright_magenta()
|
package/internals/main.rs
CHANGED
|
@@ -15,7 +15,7 @@ mod validations;
|
|
|
15
15
|
|
|
16
16
|
fn main() {
|
|
17
17
|
let root = Executor::exec("git rev-parse --show-toplevel", |cmd| cmd);
|
|
18
|
-
let config = TypescriptCommand::new(root
|
|
18
|
+
let config = TypescriptCommand::new(&root).parse_configuration();
|
|
19
19
|
let kit = RepoKit::new(root, config);
|
|
20
20
|
kit.invoke();
|
|
21
21
|
}
|
|
@@ -3,22 +3,25 @@ use std::collections::HashMap;
|
|
|
3
3
|
use serde::Deserialize;
|
|
4
4
|
|
|
5
5
|
#[derive(Debug, Deserialize, Clone)]
|
|
6
|
-
pub struct
|
|
6
|
+
pub struct CommandDefinition {
|
|
7
7
|
pub command: String,
|
|
8
8
|
pub description: String,
|
|
9
|
+
pub args: Option<HashMap<String, String>>,
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
#[derive(Debug, Deserialize, Clone)]
|
|
12
|
-
pub struct
|
|
13
|
+
pub struct RootCommand {
|
|
13
14
|
pub name: String,
|
|
14
15
|
pub command: String,
|
|
15
16
|
pub description: String,
|
|
17
|
+
pub args: Option<HashMap<String, String>>,
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
impl
|
|
19
|
-
pub fn from(name: &str, command: &
|
|
20
|
-
|
|
20
|
+
impl RootCommand {
|
|
21
|
+
pub fn from(name: &str, command: &CommandDefinition) -> RootCommand {
|
|
22
|
+
RootCommand {
|
|
21
23
|
name: name.to_string(),
|
|
24
|
+
args: command.args.clone(),
|
|
22
25
|
command: command.command.to_string(),
|
|
23
26
|
description: command.description.to_string(),
|
|
24
27
|
}
|
|
@@ -28,7 +31,7 @@ impl ParsedCommand {
|
|
|
28
31
|
#[derive(Debug, Deserialize, Clone)]
|
|
29
32
|
pub struct RepoKitConfig {
|
|
30
33
|
pub project: String,
|
|
31
|
-
pub commands: HashMap<String,
|
|
34
|
+
pub commands: HashMap<String, CommandDefinition>,
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
#[derive(Debug, Deserialize, Clone)]
|
|
@@ -37,5 +40,5 @@ pub struct RepoKitCommand {
|
|
|
37
40
|
pub owner: String,
|
|
38
41
|
pub location: String,
|
|
39
42
|
pub description: String,
|
|
40
|
-
pub commands: HashMap<String,
|
|
43
|
+
pub commands: HashMap<String, CommandDefinition>,
|
|
41
44
|
}
|
|
@@ -125,17 +125,18 @@ impl RepoKit {
|
|
|
125
125
|
)
|
|
126
126
|
.as_str(),
|
|
127
127
|
);
|
|
128
|
-
Help::
|
|
128
|
+
Help::log_external_subcommands(&command.commands, 3);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
fn log_external_command(&self, command: &RepoKitCommand) {
|
|
132
132
|
Logger::info(
|
|
133
133
|
format!(
|
|
134
|
-
"Listing available commands for {}",
|
|
135
|
-
Logger::
|
|
134
|
+
"Listing available commands for {}\n",
|
|
135
|
+
Logger::blue(&command.name)
|
|
136
136
|
)
|
|
137
137
|
.as_str(),
|
|
138
138
|
);
|
|
139
|
-
Help::
|
|
139
|
+
Help::log_external_subcommands(&command.commands, 3);
|
|
140
|
+
println!();
|
|
140
141
|
}
|
|
141
142
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repokit/core",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A knowledgebase for your repository - wrapped in a CLI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -22,12 +22,14 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build:all": "yarn lint:ts && yarn lint:rust && yarn install:rust",
|
|
24
24
|
"build:rust": "cargo build --release",
|
|
25
|
+
"grant:exec": "chmod -R +x ./installation",
|
|
25
26
|
"install:rust": "yarn build:rust && cargo install --path .",
|
|
26
27
|
"lint:rust": "cargo clippy --fix --allow-dirty",
|
|
27
28
|
"lint:ts": "yarn oxlint --type-aware --type-check --report-unused-disable-directives --fix && yarn oxfmt",
|
|
28
|
-
"postinstall": "
|
|
29
|
+
"postinstall": "yarn grant:exec && ./installation/install.sh",
|
|
29
30
|
"repokit": "yarn install:repokit && repokit",
|
|
30
|
-
"run:dev": "cargo run --package repokit --bin repokit"
|
|
31
|
+
"run:dev": "yarn symlink && cargo run --package repokit --bin repokit",
|
|
32
|
+
"symlink": "yarn grant:exec && ./installation/symlink.sh"
|
|
31
33
|
},
|
|
32
34
|
"dependencies": {
|
|
33
35
|
"@figliolia/event-emitter": "^1.1.6",
|