@repokit/core 3.0.5 → 4.0.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/Cargo.lock +96 -11
- package/Cargo.toml +2 -2
- package/installation/install.sh +37 -25
- package/internals/caches/crawl_cache.rs +124 -0
- package/internals/caches/file_cache.rs +104 -0
- package/internals/caches/mod.rs +5 -0
- package/internals/caches/repokit_version_resolver.rs +50 -0
- package/internals/caches/settings_cache.rs +73 -0
- package/internals/caches/version_cache.rs +128 -0
- package/internals/context/cache_scope.rs +76 -0
- package/internals/context/file_system.rs +66 -0
- package/internals/context/git_scope.rs +55 -0
- package/internals/context/mod.rs +5 -0
- package/internals/context/node_scope.rs +133 -0
- package/internals/context/typescript_bridge.rs +68 -0
- package/internals/executables/internal_executable.rs +8 -2
- package/internals/executables/internal_executable_definition.rs +0 -8
- package/internals/executor/executor.rs +13 -0
- package/internals/file_walker/file_walker.rs +59 -0
- package/internals/file_walker/mod.rs +1 -0
- package/internals/internal_commands/help.rs +4 -3
- package/internals/internal_commands/internal_registry.rs +14 -20
- package/internals/internal_commands/list_commands.rs +7 -16
- package/internals/internal_commands/list_owners.rs +3 -16
- package/internals/internal_commands/list_themes.rs +11 -10
- package/internals/internal_commands/list_version.rs +17 -18
- package/internals/internal_commands/locate_command.rs +11 -17
- package/internals/internal_commands/onboarder.rs +5 -16
- package/internals/internal_commands/register_command.rs +12 -20
- package/internals/internal_commands/search_commands.rs +29 -20
- package/internals/internal_commands/upgrade_repokit.rs +19 -30
- package/internals/internal_filesystem/file_builder.rs +4 -9
- package/internals/internal_filesystem/mod.rs +0 -1
- package/internals/logger/logger.rs +19 -6
- package/internals/main.rs +8 -11
- package/internals/repokit/mod.rs +1 -1
- package/internals/repokit/repokit.rs +49 -57
- package/internals/repokit/repokit_command.rs +69 -38
- package/internals/repokit/repokit_config.rs +42 -18
- package/internals/repokit/repokit_construct_validator.rs +1 -4
- package/internals/repokit/repokit_runtime.rs +43 -0
- package/internals/themes/theme_registry.rs +5 -7
- package/internals/validations/command_validations.rs +39 -62
- package/package.json +3 -3
- package/internals/configuration/configuration.rs +0 -45
- package/internals/configuration/mod.rs +0 -3
- package/internals/configuration/recovery.rs +0 -42
- package/internals/configuration/typescript_command.rs +0 -65
- package/internals/internal_filesystem/internal_filesystem.rs +0 -308
- package/internals/repokit/runtime_compiler.rs +0 -62
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
use std::collections::HashMap;
|
|
2
2
|
|
|
3
3
|
use crate::{
|
|
4
|
-
executables::
|
|
5
|
-
internal_executable::InternalExecutable, internal_executable_definition::RepoKitScope,
|
|
6
|
-
},
|
|
4
|
+
executables::internal_executable::InternalExecutable,
|
|
7
5
|
internal_commands::{
|
|
8
6
|
list_commands::ListCommands, list_owners::ListOwners, list_themes::ListThemes,
|
|
9
7
|
list_version::ListVersion, locate_command::LocateCommand, onboarder::Onboarder,
|
|
@@ -12,28 +10,24 @@ use crate::{
|
|
|
12
10
|
},
|
|
13
11
|
};
|
|
14
12
|
|
|
15
|
-
pub struct
|
|
16
|
-
scope: RepoKitScope,
|
|
17
|
-
}
|
|
13
|
+
pub struct InternalCommandRegistry;
|
|
18
14
|
|
|
19
|
-
impl
|
|
20
|
-
pub fn new(
|
|
21
|
-
|
|
22
|
-
scope: scope.clone(),
|
|
23
|
-
}
|
|
15
|
+
impl InternalCommandRegistry {
|
|
16
|
+
pub fn new() -> InternalCommandRegistry {
|
|
17
|
+
InternalCommandRegistry {}
|
|
24
18
|
}
|
|
25
19
|
|
|
26
20
|
pub fn get_all(&self) -> HashMap<String, Box<dyn InternalExecutable>> {
|
|
27
21
|
let internals: [Box<dyn InternalExecutable>; 9] = [
|
|
28
|
-
Box::new(Onboarder::new(
|
|
29
|
-
Box::new(ListCommands::new(
|
|
30
|
-
Box::new(SearchCommands::new(
|
|
31
|
-
Box::new(ListOwners::new(
|
|
32
|
-
Box::new(LocateCommand::new(
|
|
33
|
-
Box::new(RegisterCommand::new(
|
|
34
|
-
Box::new(UpgradeRepoKit::new(
|
|
35
|
-
Box::new(ListThemes::new(
|
|
36
|
-
Box::new(ListVersion::new(
|
|
22
|
+
Box::new(Onboarder::new()),
|
|
23
|
+
Box::new(ListCommands::new()),
|
|
24
|
+
Box::new(SearchCommands::new()),
|
|
25
|
+
Box::new(ListOwners::new()),
|
|
26
|
+
Box::new(LocateCommand::new()),
|
|
27
|
+
Box::new(RegisterCommand::new()),
|
|
28
|
+
Box::new(UpgradeRepoKit::new()),
|
|
29
|
+
Box::new(ListThemes::new()),
|
|
30
|
+
Box::new(ListVersion::new()),
|
|
37
31
|
];
|
|
38
32
|
HashMap::from(internals.map(|x| (x.get_definition().name.to_string(), x)))
|
|
39
33
|
}
|
|
@@ -4,26 +4,24 @@ use crate::{
|
|
|
4
4
|
executables::{
|
|
5
5
|
internal_executable::InternalExecutable,
|
|
6
6
|
internal_executable_definition::{
|
|
7
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
7
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
8
8
|
},
|
|
9
9
|
},
|
|
10
10
|
internal_commands::help::Help,
|
|
11
11
|
logger::logger::Logger,
|
|
12
|
-
repokit::repokit_command::RepoKitCommand,
|
|
12
|
+
repokit::{repokit_command::RepoKitCommand, repokit_runtime::RepoKitRuntime},
|
|
13
13
|
validations::command_validations::CommandValidations,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
pub struct ListCommands {
|
|
17
|
-
pub scope: RepoKitScope,
|
|
18
17
|
pub definition: InternalExecutableDefinition,
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
static SCOPES: [&str; 4] = ["internal", "registered", "root", "<owner>"];
|
|
22
21
|
|
|
23
22
|
impl ListCommands {
|
|
24
|
-
pub fn new(
|
|
23
|
+
pub fn new() -> ListCommands {
|
|
25
24
|
ListCommands {
|
|
26
|
-
scope: scope.clone(),
|
|
27
25
|
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
28
26
|
name: "list",
|
|
29
27
|
description: "List commands based on their scope of definition",
|
|
@@ -39,11 +37,6 @@ impl ListCommands {
|
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
fn collect_registered_commands(&self) -> HashMap<String, RepoKitCommand> {
|
|
43
|
-
let validators = CommandValidations::new(&self.scope);
|
|
44
|
-
validators.collect_and_validate_externals()
|
|
45
|
-
}
|
|
46
|
-
|
|
47
40
|
fn exit_on_invalid_scope(&self) {
|
|
48
41
|
Logger::exit_with_info(
|
|
49
42
|
format!(
|
|
@@ -66,9 +59,11 @@ impl InternalExecutable for ListCommands {
|
|
|
66
59
|
return Help::log_internal_commands(internals);
|
|
67
60
|
}
|
|
68
61
|
if scope == SCOPES[2] {
|
|
69
|
-
return
|
|
62
|
+
return RepoKitRuntime::with_runtime(|runtime| {
|
|
63
|
+
Help::log_root_commands(&runtime.configuration.commands)
|
|
64
|
+
});
|
|
70
65
|
}
|
|
71
|
-
let registered_commands =
|
|
66
|
+
let registered_commands = CommandValidations::collect_and_validate_externals();
|
|
72
67
|
if scope == SCOPES[1] {
|
|
73
68
|
return Help::log_external_commands(®istered_commands);
|
|
74
69
|
}
|
|
@@ -96,10 +91,6 @@ impl InternalExecutable for ListCommands {
|
|
|
96
91
|
Help::log_external_commands(&matches);
|
|
97
92
|
}
|
|
98
93
|
|
|
99
|
-
fn help(&self) {
|
|
100
|
-
Help::log_internal_command(&self.definition);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
94
|
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
104
95
|
&self.definition
|
|
105
96
|
}
|
|
@@ -6,24 +6,20 @@ use crate::{
|
|
|
6
6
|
executables::{
|
|
7
7
|
internal_executable::InternalExecutable,
|
|
8
8
|
internal_executable_definition::{
|
|
9
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
9
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
10
10
|
},
|
|
11
11
|
},
|
|
12
|
-
internal_commands::help::Help,
|
|
13
12
|
logger::logger::Logger,
|
|
14
|
-
repokit::repokit_command::RepoKitCommand,
|
|
15
13
|
validations::command_validations::CommandValidations,
|
|
16
14
|
};
|
|
17
15
|
|
|
18
16
|
pub struct ListOwners {
|
|
19
|
-
pub scope: RepoKitScope,
|
|
20
17
|
pub definition: InternalExecutableDefinition,
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
impl ListOwners {
|
|
24
|
-
pub fn new(
|
|
21
|
+
pub fn new() -> ListOwners {
|
|
25
22
|
ListOwners {
|
|
26
|
-
scope: scope.clone(),
|
|
27
23
|
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
28
24
|
name: "owners",
|
|
29
25
|
description: "Lists all registered command owners",
|
|
@@ -31,16 +27,11 @@ impl ListOwners {
|
|
|
31
27
|
}),
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
fn collect_registered_commands(&self) -> HashMap<String, RepoKitCommand> {
|
|
36
|
-
let validators = CommandValidations::new(&self.scope);
|
|
37
|
-
validators.collect_and_validate_externals()
|
|
38
|
-
}
|
|
39
30
|
}
|
|
40
31
|
|
|
41
32
|
impl InternalExecutable for ListOwners {
|
|
42
33
|
fn run(&self, _: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
43
|
-
let registered_commands =
|
|
34
|
+
let registered_commands = CommandValidations::collect_and_validate_externals();
|
|
44
35
|
Logger::info("Listing all command owners");
|
|
45
36
|
let mut owners: HashSet<String> = HashSet::new();
|
|
46
37
|
for (_, command) in registered_commands {
|
|
@@ -64,10 +55,6 @@ impl InternalExecutable for ListOwners {
|
|
|
64
55
|
});
|
|
65
56
|
}
|
|
66
57
|
|
|
67
|
-
fn help(&self) {
|
|
68
|
-
Help::log_internal_command(&self.definition);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
58
|
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
72
59
|
&self.definition
|
|
73
60
|
}
|
|
@@ -8,22 +8,20 @@ use crate::{
|
|
|
8
8
|
executables::{
|
|
9
9
|
internal_executable::InternalExecutable,
|
|
10
10
|
internal_executable_definition::{
|
|
11
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
11
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
12
12
|
},
|
|
13
13
|
},
|
|
14
|
-
internal_commands::help::Help,
|
|
15
14
|
logger::logger::Logger,
|
|
15
|
+
repokit::repokit_runtime::RepoKitRuntime,
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
pub struct ListThemes {
|
|
19
|
-
pub scope: RepoKitScope,
|
|
20
19
|
pub definition: InternalExecutableDefinition,
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
impl ListThemes {
|
|
24
|
-
pub fn new(
|
|
23
|
+
pub fn new() -> ListThemes {
|
|
25
24
|
ListThemes {
|
|
26
|
-
scope: scope.clone(),
|
|
27
25
|
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
28
26
|
name: "themes",
|
|
29
27
|
description: "Lists your repositories available themes",
|
|
@@ -93,7 +91,14 @@ impl InternalExecutable for ListThemes {
|
|
|
93
91
|
);
|
|
94
92
|
return self.list_themes();
|
|
95
93
|
}
|
|
96
|
-
Logger::with_registry(|mut registry| registry.set_theme(&
|
|
94
|
+
if Logger::with_registry(|mut registry| registry.set_theme(&desired_theme)) {
|
|
95
|
+
RepoKitRuntime::with_runtime(|runtime| {
|
|
96
|
+
runtime
|
|
97
|
+
.caches
|
|
98
|
+
.settings_cache
|
|
99
|
+
.store_theme_preference(&desired_theme);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
97
102
|
Logger::info(
|
|
98
103
|
format!(
|
|
99
104
|
"Your theme has been set to {}",
|
|
@@ -103,10 +108,6 @@ impl InternalExecutable for ListThemes {
|
|
|
103
108
|
);
|
|
104
109
|
}
|
|
105
110
|
|
|
106
|
-
fn help(&self) {
|
|
107
|
-
Help::log_internal_command(&self.definition);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
111
|
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
111
112
|
&self.definition
|
|
112
113
|
}
|
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
use std::collections::HashMap;
|
|
2
2
|
|
|
3
3
|
use crate::{
|
|
4
|
+
caches::version_cache::VERSION_REGEX,
|
|
4
5
|
executables::{
|
|
5
6
|
internal_executable::InternalExecutable,
|
|
6
7
|
internal_executable_definition::{
|
|
7
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
8
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
8
9
|
},
|
|
9
10
|
},
|
|
10
11
|
executor::executor::Executor,
|
|
11
|
-
internal_commands::help::Help,
|
|
12
|
-
internal_filesystem::internal_filesystem::InternalFileSystem,
|
|
13
12
|
logger::logger::Logger,
|
|
13
|
+
repokit::repokit_runtime::RepoKitRuntime,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
pub struct ListVersion {
|
|
17
|
-
pub scope: RepoKitScope,
|
|
18
17
|
pub definition: InternalExecutableDefinition,
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
impl ListVersion {
|
|
22
|
-
pub fn new(
|
|
21
|
+
pub fn new() -> ListVersion {
|
|
23
22
|
ListVersion {
|
|
24
|
-
scope: scope.clone(),
|
|
25
23
|
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
26
24
|
name: "version",
|
|
27
25
|
description: "Lists the version of repokit running in this repository",
|
|
@@ -38,22 +36,23 @@ impl ListVersion {
|
|
|
38
36
|
impl InternalExecutable for ListVersion {
|
|
39
37
|
fn run(&self, _: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
40
38
|
Logger::info("Fetching the installed version of repokit");
|
|
41
|
-
if
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
if RepoKitRuntime::with_runtime(|runtime| {
|
|
40
|
+
if VERSION_REGEX.is_match(&runtime.caches.version_cache.installed_version) {
|
|
41
|
+
self.log_version(&runtime.caches.version_cache.installed_version);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if VERSION_REGEX.is_match(&runtime.caches.version_cache.runtime_version) {
|
|
45
|
+
Logger::info("Falling back to the runtime version");
|
|
46
|
+
self.log_version(&runtime.caches.version_cache.runtime_version);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
false
|
|
50
|
+
}) {
|
|
51
|
+
return;
|
|
49
52
|
}
|
|
50
53
|
Executor::with_stdio("npm list @repokit/core", |cmd| cmd);
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
fn help(&self) {
|
|
54
|
-
Help::log_internal_command(&self.definition);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
56
|
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
58
57
|
&self.definition
|
|
59
58
|
}
|
|
@@ -4,24 +4,21 @@ use crate::{
|
|
|
4
4
|
executables::{
|
|
5
5
|
internal_executable::InternalExecutable,
|
|
6
6
|
internal_executable_definition::{
|
|
7
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
7
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
8
8
|
},
|
|
9
9
|
},
|
|
10
|
-
internal_commands::help::Help,
|
|
11
10
|
logger::logger::Logger,
|
|
12
|
-
|
|
11
|
+
repokit::repokit_runtime::RepoKitRuntime,
|
|
13
12
|
validations::command_validations::CommandValidations,
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
pub struct LocateCommand {
|
|
17
|
-
pub scope: RepoKitScope,
|
|
18
16
|
pub definition: InternalExecutableDefinition,
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
impl LocateCommand {
|
|
22
|
-
pub fn new(
|
|
20
|
+
pub fn new() -> LocateCommand {
|
|
23
21
|
LocateCommand {
|
|
24
|
-
scope: scope.clone(),
|
|
25
22
|
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
26
23
|
name: "locate",
|
|
27
24
|
description: "Locates command definitions",
|
|
@@ -31,21 +28,22 @@ impl LocateCommand {
|
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
fn search_externals(&self, query: &str) {
|
|
34
|
-
let
|
|
35
|
-
let all = finder.collect_and_validate_externals();
|
|
31
|
+
let all = CommandValidations::collect_and_validate_externals();
|
|
36
32
|
for (_, command) in all {
|
|
37
33
|
if command.name == query {
|
|
38
34
|
Logger::log_file_path(&command.location);
|
|
39
|
-
|
|
35
|
+
panic!();
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
fn search_root(&self, command: &str) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
RepoKitRuntime::with_runtime(|runtime| {
|
|
42
|
+
if runtime.configuration.commands.contains_key(command) {
|
|
43
|
+
Logger::log_file_path(format!("{}/repokit.ts", &runtime.git.root).as_str());
|
|
44
|
+
panic!();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
|
|
@@ -73,10 +71,6 @@ impl InternalExecutable for LocateCommand {
|
|
|
73
71
|
);
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
fn help(&self) {
|
|
77
|
-
Help::log_internal_command(&self.definition);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
74
|
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
81
75
|
&self.definition
|
|
82
76
|
}
|
|
@@ -4,22 +4,19 @@ use crate::{
|
|
|
4
4
|
executables::{
|
|
5
5
|
internal_executable::InternalExecutable,
|
|
6
6
|
internal_executable_definition::{
|
|
7
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
7
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
8
8
|
},
|
|
9
9
|
},
|
|
10
|
-
internal_commands::help::Help,
|
|
11
10
|
logger::logger::Logger,
|
|
12
11
|
};
|
|
13
12
|
|
|
14
13
|
pub struct Onboarder {
|
|
15
|
-
pub scope: RepoKitScope,
|
|
16
14
|
pub definition: InternalExecutableDefinition,
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
impl Onboarder {
|
|
20
|
-
pub fn new(
|
|
18
|
+
pub fn new() -> Onboarder {
|
|
21
19
|
Onboarder {
|
|
22
|
-
scope: scope.clone(),
|
|
23
20
|
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
24
21
|
name: "onboard",
|
|
25
22
|
description: "Onboarding instructions for first time users",
|
|
@@ -30,7 +27,7 @@ impl Onboarder {
|
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
impl InternalExecutable for Onboarder {
|
|
33
|
-
fn run(&self,
|
|
30
|
+
fn run(&self, _args: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
34
31
|
Logger::info(
|
|
35
32
|
format!(
|
|
36
33
|
"Welcome to {}",
|
|
@@ -46,23 +43,15 @@ impl InternalExecutable for Onboarder {
|
|
|
46
43
|
);
|
|
47
44
|
Logger::log_file_path("repokit register ./path/to/your-feature");
|
|
48
45
|
Logger::info(
|
|
49
|
-
"This command creates a tooling definition for your feature
|
|
46
|
+
"This command creates a tooling definition for your feature designed to live along side the feature's implementation",
|
|
50
47
|
);
|
|
51
48
|
Logger::info(
|
|
52
49
|
format!(
|
|
53
|
-
"The {} CLI will automatically detect these files and add them to its toolchain",
|
|
50
|
+
"The {} CLI will automatically detect these files and add them to its toolchain - making them available to your entire team",
|
|
54
51
|
Logger::with_theme(|theme| theme.highlight("Repokit"))
|
|
55
52
|
)
|
|
56
53
|
.as_str(),
|
|
57
54
|
);
|
|
58
|
-
Logger::info(
|
|
59
|
-
format!("As your codebase grows, your {} CLI will continue to track all of the published workflows created by your team", Logger::with_theme(|theme|theme.highlight("Repokit"))).as_str()
|
|
60
|
-
);
|
|
61
|
-
Logger::space_around("It's your living source of knowledge and documentation");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
fn help(&self) {
|
|
65
|
-
Help::log_internal_command(&self.definition);
|
|
66
55
|
}
|
|
67
56
|
|
|
68
57
|
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
@@ -1,31 +1,25 @@
|
|
|
1
1
|
use normalize_path::NormalizePath;
|
|
2
|
-
use std::{
|
|
3
|
-
collections::HashMap,
|
|
4
|
-
path::{Path, PathBuf},
|
|
5
|
-
};
|
|
2
|
+
use std::{collections::HashMap, path::PathBuf};
|
|
6
3
|
|
|
7
4
|
use crate::{
|
|
8
5
|
executables::{
|
|
9
6
|
internal_executable::InternalExecutable,
|
|
10
7
|
internal_executable_definition::{
|
|
11
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
8
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
12
9
|
},
|
|
13
10
|
},
|
|
14
|
-
|
|
15
|
-
internal_filesystem::{file_builder::FileBuilder, internal_filesystem::InternalFileSystem},
|
|
11
|
+
internal_filesystem::file_builder::FileBuilder,
|
|
16
12
|
logger::logger::Logger,
|
|
17
|
-
|
|
13
|
+
repokit::repokit_runtime::RepoKitRuntime,
|
|
18
14
|
};
|
|
19
15
|
|
|
20
16
|
pub struct RegisterCommand {
|
|
21
|
-
pub scope: RepoKitScope,
|
|
22
17
|
pub definition: InternalExecutableDefinition,
|
|
23
18
|
}
|
|
24
19
|
|
|
25
20
|
impl RegisterCommand {
|
|
26
|
-
pub fn new(
|
|
21
|
+
pub fn new() -> RegisterCommand {
|
|
27
22
|
RegisterCommand {
|
|
28
|
-
scope: scope.clone(),
|
|
29
23
|
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
30
24
|
name: "register",
|
|
31
25
|
description: "Creates new Repokit commands",
|
|
@@ -45,7 +39,9 @@ impl RegisterCommand {
|
|
|
45
39
|
if path_arg.is_empty() {
|
|
46
40
|
RegisterCommand::exit_on_missing_path();
|
|
47
41
|
}
|
|
48
|
-
let path =
|
|
42
|
+
let path = RepoKitRuntime::with_runtime(|runtime| {
|
|
43
|
+
runtime.files.git_root_path.join(&path_arg).normalize()
|
|
44
|
+
});
|
|
49
45
|
if !path.exists() {
|
|
50
46
|
Logger::info(
|
|
51
47
|
format!(
|
|
@@ -68,11 +64,10 @@ impl RegisterCommand {
|
|
|
68
64
|
)
|
|
69
65
|
.as_str(),
|
|
70
66
|
);
|
|
71
|
-
Logger::
|
|
67
|
+
Logger::exit_with_info(format!(
|
|
72
68
|
"You can append additional commands to the existing {} instance or export another one",
|
|
73
69
|
Logger::with_theme(|theme| theme.highlight("RepoKitCommand"))
|
|
74
70
|
).as_str());
|
|
75
|
-
PostProcessor::get().flush();
|
|
76
71
|
}
|
|
77
72
|
command_path.clone()
|
|
78
73
|
}
|
|
@@ -88,8 +83,9 @@ impl InternalExecutable for RegisterCommand {
|
|
|
88
83
|
fn run(&self, args: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
89
84
|
Logger::info("Registering a new command");
|
|
90
85
|
let command_path = self.validate_path(args);
|
|
91
|
-
let mut source =
|
|
92
|
-
|
|
86
|
+
let mut source = RepoKitRuntime::with_runtime(|runtime| {
|
|
87
|
+
runtime.files.resolve_template("command_template.txt")
|
|
88
|
+
});
|
|
93
89
|
let mut target = FileBuilder::create(&command_path, |_| Logger::file_create_error());
|
|
94
90
|
FileBuilder::copy_to(&mut source, &mut target, |_| Logger::file_write_error());
|
|
95
91
|
Logger::info("Creating command file");
|
|
@@ -97,10 +93,6 @@ impl InternalExecutable for RegisterCommand {
|
|
|
97
93
|
Logger::log_file_path(command_path.to_str().expect("path"));
|
|
98
94
|
}
|
|
99
95
|
|
|
100
|
-
fn help(&self) {
|
|
101
|
-
Help::log_internal_command(&self.definition);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
96
|
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
105
97
|
&self.definition
|
|
106
98
|
}
|
|
@@ -5,24 +5,25 @@ use crate::{
|
|
|
5
5
|
executables::{
|
|
6
6
|
internal_executable::InternalExecutable,
|
|
7
7
|
internal_executable_definition::{
|
|
8
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
8
|
+
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
9
9
|
},
|
|
10
10
|
},
|
|
11
11
|
internal_commands::help::Help,
|
|
12
12
|
logger::logger::Logger,
|
|
13
|
-
repokit::{
|
|
13
|
+
repokit::{
|
|
14
|
+
command_definition::CommandDefinition, repokit_command::RepoKitCommand,
|
|
15
|
+
repokit_runtime::RepoKitRuntime,
|
|
16
|
+
},
|
|
14
17
|
validations::command_validations::CommandValidations,
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
pub struct SearchCommands {
|
|
18
|
-
pub scope: RepoKitScope,
|
|
19
21
|
pub definition: InternalExecutableDefinition,
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
impl SearchCommands {
|
|
23
|
-
pub fn new(
|
|
25
|
+
pub fn new() -> SearchCommands {
|
|
24
26
|
SearchCommands {
|
|
25
|
-
scope: scope.clone(),
|
|
26
27
|
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
27
28
|
name: "search",
|
|
28
29
|
description: "Retrieve commands that match any search query",
|
|
@@ -61,9 +62,10 @@ impl SearchCommands {
|
|
|
61
62
|
if command.owner.to_lowercase().contains(query) {
|
|
62
63
|
return true;
|
|
63
64
|
}
|
|
65
|
+
let git_root = RepoKitRuntime::with_runtime(|runtime| runtime.git.root.clone());
|
|
64
66
|
if command
|
|
65
67
|
.location
|
|
66
|
-
.replace(
|
|
68
|
+
.replace(&git_root, "")
|
|
67
69
|
.to_lowercase()
|
|
68
70
|
.contains(query)
|
|
69
71
|
{
|
|
@@ -72,20 +74,29 @@ impl SearchCommands {
|
|
|
72
74
|
if command.description.to_lowercase().contains(query) {
|
|
73
75
|
return true;
|
|
74
76
|
}
|
|
75
|
-
for (
|
|
76
|
-
if
|
|
77
|
+
for (command_name, definition) in &command.commands {
|
|
78
|
+
if command_name.to_lowercase().contains(query) || self.search_command(query, definition)
|
|
79
|
+
{
|
|
77
80
|
return true;
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
false
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
fn search_command(&self, query: &str,
|
|
84
|
-
if
|
|
85
|
-
||
|
|
86
|
+
fn search_command(&self, query: &str, definition: &CommandDefinition) -> bool {
|
|
87
|
+
if definition.command.to_lowercase().contains(query)
|
|
88
|
+
|| definition.description.to_lowercase().contains(query)
|
|
86
89
|
{
|
|
87
90
|
return true;
|
|
88
91
|
}
|
|
92
|
+
if let Some(args) = &definition.args {
|
|
93
|
+
for (flag, description) in args {
|
|
94
|
+
if flag.to_lowercase().contains(query) || description.to_lowercase().contains(query)
|
|
95
|
+
{
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
89
100
|
false
|
|
90
101
|
}
|
|
91
102
|
|
|
@@ -155,15 +166,17 @@ impl InternalExecutable for SearchCommands {
|
|
|
155
166
|
Logger::exit_with_error("Please specify a search string to query with");
|
|
156
167
|
}
|
|
157
168
|
let query = args.join(" ").to_lowercase();
|
|
158
|
-
let externals = CommandValidations::
|
|
169
|
+
let externals = CommandValidations::collect_and_validate_externals();
|
|
159
170
|
let mut root_results: HashMap<String, CommandDefinition> = HashMap::new();
|
|
160
171
|
let mut internal_results: HashMap<String, &Box<dyn InternalExecutable>> = HashMap::new();
|
|
161
172
|
let mut external_results: HashMap<String, RepoKitCommand> = HashMap::new();
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
173
|
+
RepoKitRuntime::with_runtime(|runtime| {
|
|
174
|
+
for (command, script) in &runtime.configuration.commands {
|
|
175
|
+
if self.search_command(&query, script) {
|
|
176
|
+
root_results.insert(command.clone(), script.clone());
|
|
177
|
+
}
|
|
165
178
|
}
|
|
166
|
-
}
|
|
179
|
+
});
|
|
167
180
|
for (name, command) in internals {
|
|
168
181
|
if self.search_internal(&query, command) {
|
|
169
182
|
internal_results.insert(name.clone(), command);
|
|
@@ -182,10 +195,6 @@ impl InternalExecutable for SearchCommands {
|
|
|
182
195
|
self.log_external_results(&external_results);
|
|
183
196
|
}
|
|
184
197
|
|
|
185
|
-
fn help(&self) {
|
|
186
|
-
Help::log_internal_command(&self.definition);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
198
|
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
190
199
|
&self.definition
|
|
191
200
|
}
|