@repokit/core 4.0.6 → 5.0.1
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/README.md +17 -4
- package/dist/types.d.mts +1 -1
- package/externals/TSCompiler.ts +1 -2
- package/externals/types.ts +1 -1
- package/package.json +29 -19
- package/Cargo.lock +0 -1609
- package/Cargo.toml +0 -23
- package/installation/install.sh +0 -99
- package/internals/argv/argv.rs +0 -132
- package/internals/argv/mod.rs +0 -1
- package/internals/caches/crawl_cache.rs +0 -126
- package/internals/caches/file_cache.rs +0 -104
- package/internals/caches/mod.rs +0 -6
- package/internals/caches/old_cache.rs +0 -35
- package/internals/caches/repokit_version_resolver.rs +0 -50
- package/internals/caches/settings_cache.rs +0 -73
- package/internals/caches/version_cache.rs +0 -142
- package/internals/context/cache_scope.rs +0 -71
- package/internals/context/file_system.rs +0 -66
- package/internals/context/git_scope.rs +0 -55
- package/internals/context/mod.rs +0 -5
- package/internals/context/node_scope.rs +0 -133
- package/internals/context/typescript_bridge.rs +0 -84
- package/internals/executables/internal_executable.rs +0 -15
- package/internals/executables/internal_executable_definition.rs +0 -40
- package/internals/executables/mod.rs +0 -2
- package/internals/executor/executor.rs +0 -88
- package/internals/executor/mod.rs +0 -1
- package/internals/file_walker/file_walker.rs +0 -69
- package/internals/file_walker/mod.rs +0 -2
- package/internals/file_walker/walker.rs +0 -114
- package/internals/internal_commands/help.rs +0 -174
- package/internals/internal_commands/internal_registry.rs +0 -34
- package/internals/internal_commands/list_commands.rs +0 -97
- package/internals/internal_commands/list_owners.rs +0 -61
- package/internals/internal_commands/list_themes.rs +0 -114
- package/internals/internal_commands/list_version.rs +0 -59
- package/internals/internal_commands/locate_command.rs +0 -77
- package/internals/internal_commands/mod.rs +0 -11
- package/internals/internal_commands/onboarder.rs +0 -60
- package/internals/internal_commands/register_command.rs +0 -99
- package/internals/internal_commands/search_commands.rs +0 -201
- package/internals/internal_commands/upgrade_repokit.rs +0 -71
- package/internals/internal_filesystem/file_builder.rs +0 -56
- package/internals/internal_filesystem/mod.rs +0 -1
- package/internals/logger/logger.rs +0 -163
- package/internals/logger/mod.rs +0 -1
- package/internals/main.rs +0 -23
- package/internals/post_processing/mod.rs +0 -1
- package/internals/post_processing/post_processor.rs +0 -37
- package/internals/repokit/command_definition.rs +0 -11
- package/internals/repokit/mod.rs +0 -6
- package/internals/repokit/repokit.rs +0 -146
- package/internals/repokit/repokit_command.rs +0 -101
- package/internals/repokit/repokit_config.rs +0 -101
- package/internals/repokit/repokit_construct_validator.rs +0 -11
- package/internals/repokit/repokit_runtime.rs +0 -43
- package/internals/themes/built_in_themes/mod.rs +0 -3
- package/internals/themes/built_in_themes/money.rs +0 -41
- package/internals/themes/built_in_themes/seeing_red.rs +0 -41
- package/internals/themes/built_in_themes/the_blues.rs +0 -41
- package/internals/themes/mod.rs +0 -5
- package/internals/themes/theme.rs +0 -108
- package/internals/themes/theme_colors.rs +0 -32
- package/internals/themes/theme_inputs.rs +0 -35
- package/internals/themes/theme_registry.rs +0 -123
- package/internals/validations/command_validations.rs +0 -127
- package/internals/validations/mod.rs +0 -1
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
|
|
3
|
-
use alphanumeric_sort::sort_str_slice;
|
|
4
|
-
use colored::Colorize;
|
|
5
|
-
|
|
6
|
-
use crate::{
|
|
7
|
-
argv::argv::{Argv, ArgvOption, ArgvType},
|
|
8
|
-
executables::{
|
|
9
|
-
internal_executable::InternalExecutable,
|
|
10
|
-
internal_executable_definition::{
|
|
11
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
logger::logger::Logger,
|
|
15
|
-
repokit::repokit_runtime::RepoKitRuntime,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
pub struct ListThemes {
|
|
19
|
-
pub definition: InternalExecutableDefinition,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
impl ListThemes {
|
|
23
|
-
pub fn new() -> ListThemes {
|
|
24
|
-
ListThemes {
|
|
25
|
-
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
26
|
-
name: "themes",
|
|
27
|
-
description: "Lists your repositories available themes",
|
|
28
|
-
args: [(
|
|
29
|
-
"(--set | -s)",
|
|
30
|
-
"An optional flag allowing you to set your theme",
|
|
31
|
-
)],
|
|
32
|
-
}),
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
fn list_themes(&self) {
|
|
37
|
-
Logger::info("Listing available themes");
|
|
38
|
-
let themes = Logger::with_registry(|registry| registry.themes.clone());
|
|
39
|
-
let current_theme = Logger::with_theme(|theme| theme.name.clone());
|
|
40
|
-
let mut keys: Vec<&String> = themes.keys().collect();
|
|
41
|
-
sort_str_slice(&mut keys);
|
|
42
|
-
Logger::with_surrounding_space(|| {
|
|
43
|
-
let mut pointer = 1;
|
|
44
|
-
for name in &keys {
|
|
45
|
-
let mut post_fix = "";
|
|
46
|
-
let is_active_theme = name.as_str() == current_theme;
|
|
47
|
-
if is_active_theme {
|
|
48
|
-
post_fix = " <--- selected";
|
|
49
|
-
}
|
|
50
|
-
println!(
|
|
51
|
-
"{}{}{}",
|
|
52
|
-
Logger::indent(None),
|
|
53
|
-
Logger::with_theme(|theme| {
|
|
54
|
-
let name_text = if is_active_theme {
|
|
55
|
-
theme.highlight(name).bold()
|
|
56
|
-
} else {
|
|
57
|
-
theme.highlight(name)
|
|
58
|
-
};
|
|
59
|
-
format!("{}. {}", pointer.to_string().as_str(), name_text)
|
|
60
|
-
}),
|
|
61
|
-
post_fix
|
|
62
|
-
);
|
|
63
|
-
pointer += 1;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
impl InternalExecutable for ListThemes {
|
|
70
|
-
fn run(&self, args: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
71
|
-
let argv = Argv::new(
|
|
72
|
-
[ArgvOption {
|
|
73
|
-
name: "set",
|
|
74
|
-
value_type: ArgvType::String,
|
|
75
|
-
short: None,
|
|
76
|
-
multiple: None,
|
|
77
|
-
}],
|
|
78
|
-
Some(args),
|
|
79
|
-
);
|
|
80
|
-
if !argv.has("set") {
|
|
81
|
-
return self.list_themes();
|
|
82
|
-
}
|
|
83
|
-
let desired_theme = argv.get_first("set");
|
|
84
|
-
if Logger::with_registry(|registry| !registry.has(&desired_theme)) {
|
|
85
|
-
Logger::error(
|
|
86
|
-
format!(
|
|
87
|
-
"I'm not aware of a theme named {}",
|
|
88
|
-
Logger::with_theme(|theme| theme.highlight(&desired_theme))
|
|
89
|
-
)
|
|
90
|
-
.as_str(),
|
|
91
|
-
);
|
|
92
|
-
return self.list_themes();
|
|
93
|
-
}
|
|
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
|
-
}
|
|
102
|
-
Logger::info(
|
|
103
|
-
format!(
|
|
104
|
-
"Your theme has been set to {}",
|
|
105
|
-
Logger::with_theme(|theme| theme.highlight(&desired_theme))
|
|
106
|
-
)
|
|
107
|
-
.as_str(),
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
112
|
-
&self.definition
|
|
113
|
-
}
|
|
114
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
|
|
3
|
-
use crate::{
|
|
4
|
-
caches::version_cache::VERSION_REGEX,
|
|
5
|
-
executables::{
|
|
6
|
-
internal_executable::InternalExecutable,
|
|
7
|
-
internal_executable_definition::{
|
|
8
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
executor::executor::Executor,
|
|
12
|
-
logger::logger::Logger,
|
|
13
|
-
repokit::repokit_runtime::RepoKitRuntime,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
pub struct ListVersion {
|
|
17
|
-
pub definition: InternalExecutableDefinition,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
impl ListVersion {
|
|
21
|
-
pub fn new() -> ListVersion {
|
|
22
|
-
ListVersion {
|
|
23
|
-
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
24
|
-
name: "version",
|
|
25
|
-
description: "Lists the version of repokit running in this repository",
|
|
26
|
-
args: [],
|
|
27
|
-
}),
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
fn log_version(&self, version: &str) {
|
|
32
|
-
Logger::info(format!("{}", Logger::with_theme(|theme| theme.highlight(version))).as_str());
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
impl InternalExecutable for ListVersion {
|
|
37
|
-
fn run(&self, _: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
38
|
-
Logger::info("Fetching the installed version of repokit");
|
|
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;
|
|
52
|
-
}
|
|
53
|
-
Executor::with_stdio("npm list @repokit/core", |cmd| cmd);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
57
|
-
&self.definition
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
|
|
3
|
-
use crate::{
|
|
4
|
-
executables::{
|
|
5
|
-
internal_executable::InternalExecutable,
|
|
6
|
-
internal_executable_definition::{
|
|
7
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
logger::logger::Logger,
|
|
11
|
-
repokit::repokit_runtime::RepoKitRuntime,
|
|
12
|
-
validations::command_validations::CommandValidations,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
pub struct LocateCommand {
|
|
16
|
-
pub definition: InternalExecutableDefinition,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
impl LocateCommand {
|
|
20
|
-
pub fn new() -> LocateCommand {
|
|
21
|
-
LocateCommand {
|
|
22
|
-
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
23
|
-
name: "locate",
|
|
24
|
-
description: "Locates command definitions",
|
|
25
|
-
args: [("<name>", "The name of a registered command")],
|
|
26
|
-
}),
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
fn search_externals(&self, query: &str) {
|
|
31
|
-
let all = CommandValidations::collect_and_validate_externals();
|
|
32
|
-
for (_, command) in all {
|
|
33
|
-
if command.name == query {
|
|
34
|
-
Logger::log_file_path(&command.location);
|
|
35
|
-
panic!();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fn search_root(&self, command: &str) {
|
|
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
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
impl InternalExecutable for LocateCommand {
|
|
51
|
-
fn run(&self, args: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
52
|
-
if args.is_empty() {
|
|
53
|
-
Logger::exit_with_info("Please specify a command to locate");
|
|
54
|
-
}
|
|
55
|
-
let command = &args[0];
|
|
56
|
-
Logger::info(
|
|
57
|
-
format!(
|
|
58
|
-
"Locating a command named {}",
|
|
59
|
-
Logger::with_theme(|theme| theme.highlight(command))
|
|
60
|
-
)
|
|
61
|
-
.as_str(),
|
|
62
|
-
);
|
|
63
|
-
self.search_externals(command);
|
|
64
|
-
self.search_root(command);
|
|
65
|
-
Logger::exit_with_error(
|
|
66
|
-
format!(
|
|
67
|
-
"I could not find a command named {}",
|
|
68
|
-
Logger::with_theme(|theme| theme.highlight(command))
|
|
69
|
-
)
|
|
70
|
-
.as_str(),
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
75
|
-
&self.definition
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
pub mod help;
|
|
2
|
-
pub mod internal_registry;
|
|
3
|
-
pub mod list_commands;
|
|
4
|
-
pub mod list_owners;
|
|
5
|
-
pub mod list_themes;
|
|
6
|
-
pub mod list_version;
|
|
7
|
-
pub mod locate_command;
|
|
8
|
-
pub mod onboarder;
|
|
9
|
-
pub mod register_command;
|
|
10
|
-
pub mod search_commands;
|
|
11
|
-
pub mod upgrade_repokit;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
|
|
3
|
-
use crate::{
|
|
4
|
-
executables::{
|
|
5
|
-
internal_executable::InternalExecutable,
|
|
6
|
-
internal_executable_definition::{
|
|
7
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
logger::logger::Logger,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
pub struct Onboarder {
|
|
14
|
-
pub definition: InternalExecutableDefinition,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
impl Onboarder {
|
|
18
|
-
pub fn new() -> Onboarder {
|
|
19
|
-
Onboarder {
|
|
20
|
-
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
21
|
-
name: "onboard",
|
|
22
|
-
description: "Onboarding instructions for first time users",
|
|
23
|
-
args: [],
|
|
24
|
-
}),
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
impl InternalExecutable for Onboarder {
|
|
30
|
-
fn run(&self, _args: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
31
|
-
Logger::info(
|
|
32
|
-
format!(
|
|
33
|
-
"Welcome to {}",
|
|
34
|
-
Logger::with_theme(|theme| theme.highlight("Repokit"))
|
|
35
|
-
)
|
|
36
|
-
.as_str(),
|
|
37
|
-
);
|
|
38
|
-
Logger::info(
|
|
39
|
-
"Repokit is a tool designed to self-document and publish developer facing workflows in a single CLI",
|
|
40
|
-
);
|
|
41
|
-
Logger::info(
|
|
42
|
-
format!("As you develop new features in your codebase, you can publish commands, API's, and tools to the {} CLI by running", Logger::with_theme(|theme|theme.highlight("Repokit"))).as_str()
|
|
43
|
-
);
|
|
44
|
-
Logger::log_file_path("repokit register ./path/to/your-feature");
|
|
45
|
-
Logger::info(
|
|
46
|
-
"This command creates a tooling definition for your feature designed to live along side the feature's implementation",
|
|
47
|
-
);
|
|
48
|
-
Logger::info(
|
|
49
|
-
format!(
|
|
50
|
-
"The {} CLI will automatically detect these files and add them to its toolchain - making them available to your entire team",
|
|
51
|
-
Logger::with_theme(|theme| theme.highlight("Repokit"))
|
|
52
|
-
)
|
|
53
|
-
.as_str(),
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
58
|
-
&self.definition
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
use normalize_path::NormalizePath;
|
|
2
|
-
use std::{collections::HashMap, path::PathBuf};
|
|
3
|
-
|
|
4
|
-
use crate::{
|
|
5
|
-
executables::{
|
|
6
|
-
internal_executable::InternalExecutable,
|
|
7
|
-
internal_executable_definition::{
|
|
8
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
internal_filesystem::file_builder::FileBuilder,
|
|
12
|
-
logger::logger::Logger,
|
|
13
|
-
repokit::repokit_runtime::RepoKitRuntime,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
pub struct RegisterCommand {
|
|
17
|
-
pub definition: InternalExecutableDefinition,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
impl RegisterCommand {
|
|
21
|
-
pub fn new() -> RegisterCommand {
|
|
22
|
-
RegisterCommand {
|
|
23
|
-
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
24
|
-
name: "register",
|
|
25
|
-
description: "Creates new Repokit commands",
|
|
26
|
-
args: [(
|
|
27
|
-
"<path>",
|
|
28
|
-
"A relative path to your preferred command location",
|
|
29
|
-
)],
|
|
30
|
-
}),
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
fn validate_path(&self, args: Vec<String>) -> PathBuf {
|
|
35
|
-
if args.is_empty() {
|
|
36
|
-
RegisterCommand::exit_on_missing_path();
|
|
37
|
-
}
|
|
38
|
-
let path_arg = args[0].clone();
|
|
39
|
-
if path_arg.is_empty() {
|
|
40
|
-
RegisterCommand::exit_on_missing_path();
|
|
41
|
-
}
|
|
42
|
-
let path = RepoKitRuntime::with_runtime(|runtime| {
|
|
43
|
-
runtime.files.git_root_path.join(&path_arg).normalize()
|
|
44
|
-
});
|
|
45
|
-
if !path.exists() {
|
|
46
|
-
Logger::info(
|
|
47
|
-
format!(
|
|
48
|
-
"Creating the path {} in your file system",
|
|
49
|
-
Logger::with_theme(|theme| theme.highlight(path_arg.as_str()))
|
|
50
|
-
)
|
|
51
|
-
.as_str(),
|
|
52
|
-
);
|
|
53
|
-
FileBuilder::create_dir_all(&path, |_| Logger::file_directory_error());
|
|
54
|
-
}
|
|
55
|
-
if !path.is_dir() {
|
|
56
|
-
RegisterCommand::exit_on_missing_path();
|
|
57
|
-
}
|
|
58
|
-
let command_path = &path.join("Commands.ts");
|
|
59
|
-
if command_path.exists() {
|
|
60
|
-
Logger::error(
|
|
61
|
-
format!(
|
|
62
|
-
"A {} file already exists in this directory",
|
|
63
|
-
Logger::with_theme(|theme| theme.highlight("Commands.ts"))
|
|
64
|
-
)
|
|
65
|
-
.as_str(),
|
|
66
|
-
);
|
|
67
|
-
Logger::exit_with_info(format!(
|
|
68
|
-
"You can append additional commands to the existing {} instance or export another one",
|
|
69
|
-
Logger::with_theme(|theme| theme.highlight("RepoKitCommand"))
|
|
70
|
-
).as_str());
|
|
71
|
-
}
|
|
72
|
-
command_path.clone()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
fn exit_on_missing_path() {
|
|
76
|
-
Logger::exit_with_error(
|
|
77
|
-
"Please specify a path to a directory relative to the root of your repository",
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
impl InternalExecutable for RegisterCommand {
|
|
83
|
-
fn run(&self, args: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
84
|
-
Logger::info("Registering a new command");
|
|
85
|
-
let command_path = self.validate_path(args);
|
|
86
|
-
let mut source = RepoKitRuntime::with_runtime(|runtime| {
|
|
87
|
-
runtime.files.resolve_template("command_template.txt")
|
|
88
|
-
});
|
|
89
|
-
let mut target = FileBuilder::create(&command_path, |_| Logger::file_create_error());
|
|
90
|
-
FileBuilder::copy_to(&mut source, &mut target, |_| Logger::file_write_error());
|
|
91
|
-
Logger::info("Creating command file");
|
|
92
|
-
Logger::info("Please fill out your command file located at:");
|
|
93
|
-
Logger::log_file_path(command_path.to_str().expect("path"));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
97
|
-
&self.definition
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
use alphanumeric_sort::sort_slice_by_str_key;
|
|
2
|
-
use std::collections::HashMap;
|
|
3
|
-
|
|
4
|
-
use crate::{
|
|
5
|
-
executables::{
|
|
6
|
-
internal_executable::InternalExecutable,
|
|
7
|
-
internal_executable_definition::{
|
|
8
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
internal_commands::help::Help,
|
|
12
|
-
logger::logger::Logger,
|
|
13
|
-
repokit::{
|
|
14
|
-
command_definition::CommandDefinition, repokit_command::RepoKitCommand,
|
|
15
|
-
repokit_runtime::RepoKitRuntime,
|
|
16
|
-
},
|
|
17
|
-
validations::command_validations::CommandValidations,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
pub struct SearchCommands {
|
|
21
|
-
pub definition: InternalExecutableDefinition,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
impl SearchCommands {
|
|
25
|
-
pub fn new() -> SearchCommands {
|
|
26
|
-
SearchCommands {
|
|
27
|
-
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
28
|
-
name: "search",
|
|
29
|
-
description: "Retrieve commands that match any search query",
|
|
30
|
-
args: [(
|
|
31
|
-
"<query>",
|
|
32
|
-
"A search string to match against command names, descriptions, arguments, or owner",
|
|
33
|
-
)],
|
|
34
|
-
}),
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fn search_internal(&self, query: &str, command: &Box<dyn InternalExecutable>) -> bool {
|
|
39
|
-
let config = command.get_definition();
|
|
40
|
-
if config.name.to_lowercase().contains(query) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
if config.description.to_lowercase().contains(query) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
if let Some(args) = &config.args {
|
|
47
|
-
for (arg, description) in args {
|
|
48
|
-
if arg.to_lowercase().contains(query) || description.to_lowercase().contains(query)
|
|
49
|
-
{
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
false
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
fn search_external(&self, query: &str, command: &RepoKitCommand) -> bool {
|
|
59
|
-
if command.name.to_lowercase().contains(query) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
if command.owner.to_lowercase().contains(query) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
let git_root = RepoKitRuntime::with_runtime(|runtime| runtime.git.root.clone());
|
|
66
|
-
if command
|
|
67
|
-
.location
|
|
68
|
-
.replace(&git_root, "")
|
|
69
|
-
.to_lowercase()
|
|
70
|
-
.contains(query)
|
|
71
|
-
{
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
if command.description.to_lowercase().contains(query) {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
for (command_name, definition) in &command.commands {
|
|
78
|
-
if command_name.to_lowercase().contains(query) || self.search_command(query, definition)
|
|
79
|
-
{
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
false
|
|
84
|
-
}
|
|
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)
|
|
89
|
-
{
|
|
90
|
-
return true;
|
|
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
|
-
}
|
|
100
|
-
false
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
fn log_root_results(&self, root_results: &HashMap<String, CommandDefinition>) {
|
|
104
|
-
let total = root_results.len();
|
|
105
|
-
let plural_appendage = if total == 1 { "" } else { "s" };
|
|
106
|
-
if !root_results.is_empty() {
|
|
107
|
-
Help::log_root_commands(root_results);
|
|
108
|
-
}
|
|
109
|
-
Logger::info(
|
|
110
|
-
format!(
|
|
111
|
-
"Matched {} command{} in your repokit config",
|
|
112
|
-
Logger::with_theme(|theme| theme.highlight(total.to_string().as_str())),
|
|
113
|
-
plural_appendage,
|
|
114
|
-
)
|
|
115
|
-
.as_str(),
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
fn log_internal_results(
|
|
120
|
-
&self,
|
|
121
|
-
internal_results: &HashMap<String, &Box<dyn InternalExecutable>>,
|
|
122
|
-
) {
|
|
123
|
-
let total = internal_results.len();
|
|
124
|
-
let plural_appendage = if total == 1 { "" } else { "s" };
|
|
125
|
-
if !internal_results.is_empty() {
|
|
126
|
-
let mut sorted_internals: Vec<&&Box<dyn InternalExecutable>> =
|
|
127
|
-
internal_results.values().collect();
|
|
128
|
-
sort_slice_by_str_key(&mut sorted_internals, |x| &x.get_definition().name);
|
|
129
|
-
Logger::space_around("Internal Commands:");
|
|
130
|
-
for internal in sorted_internals {
|
|
131
|
-
internal.help();
|
|
132
|
-
println!();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
Logger::info(
|
|
136
|
-
format!(
|
|
137
|
-
"Matched {} internal command{}",
|
|
138
|
-
Logger::with_theme(|theme| theme.highlight(total.to_string().as_str())),
|
|
139
|
-
plural_appendage,
|
|
140
|
-
)
|
|
141
|
-
.as_str(),
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
fn log_external_results(&self, external_commands: &HashMap<String, RepoKitCommand>) {
|
|
146
|
-
let total = external_commands.len();
|
|
147
|
-
let plural_appendage = if total == 1 { "" } else { "s" };
|
|
148
|
-
if !external_commands.is_empty() {
|
|
149
|
-
Help::log_external_commands(external_commands);
|
|
150
|
-
}
|
|
151
|
-
Logger::info(
|
|
152
|
-
format!(
|
|
153
|
-
"Matched {} registered command{}",
|
|
154
|
-
Logger::with_theme(|theme| theme.highlight(total.to_string().as_str())),
|
|
155
|
-
plural_appendage,
|
|
156
|
-
)
|
|
157
|
-
.as_str(),
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
impl InternalExecutable for SearchCommands {
|
|
163
|
-
fn run(&self, args: Vec<String>, internals: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
164
|
-
Logger::info("Searching commands");
|
|
165
|
-
if args.is_empty() {
|
|
166
|
-
Logger::exit_with_error("Please specify a search string to query with");
|
|
167
|
-
}
|
|
168
|
-
let query = args.join(" ").to_lowercase();
|
|
169
|
-
let externals = CommandValidations::collect_and_validate_externals();
|
|
170
|
-
let mut root_results: HashMap<String, CommandDefinition> = HashMap::new();
|
|
171
|
-
let mut internal_results: HashMap<String, &Box<dyn InternalExecutable>> = HashMap::new();
|
|
172
|
-
let mut external_results: HashMap<String, RepoKitCommand> = HashMap::new();
|
|
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
|
-
}
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
for (name, command) in internals {
|
|
181
|
-
if self.search_internal(&query, command) {
|
|
182
|
-
internal_results.insert(name.clone(), command);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
for (name, command) in externals {
|
|
186
|
-
if self.search_external(&query, &command) {
|
|
187
|
-
external_results.insert(name, command);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if root_results.is_empty() && internal_results.is_empty() && external_results.is_empty() {
|
|
191
|
-
Logger::exit_with_info("No matched commands");
|
|
192
|
-
}
|
|
193
|
-
self.log_root_results(&root_results);
|
|
194
|
-
self.log_internal_results(&internal_results);
|
|
195
|
-
self.log_external_results(&external_results);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
199
|
-
&self.definition
|
|
200
|
-
}
|
|
201
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
|
|
3
|
-
use terminal_spinners::{BOUNCING_BALL, SpinnerBuilder};
|
|
4
|
-
|
|
5
|
-
use crate::{
|
|
6
|
-
executables::{
|
|
7
|
-
internal_executable::InternalExecutable,
|
|
8
|
-
internal_executable_definition::{
|
|
9
|
-
InternalExecutableDefinition, InternalExecutableDefinitionInput,
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
executor::executor::Executor,
|
|
13
|
-
logger::logger::Logger,
|
|
14
|
-
repokit::repokit_runtime::RepoKitRuntime,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
pub struct UpgradeRepoKit {
|
|
18
|
-
pub definition: InternalExecutableDefinition,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
impl UpgradeRepoKit {
|
|
22
|
-
pub fn new() -> UpgradeRepoKit {
|
|
23
|
-
UpgradeRepoKit {
|
|
24
|
-
definition: InternalExecutableDefinition::define(InternalExecutableDefinitionInput {
|
|
25
|
-
name: "upgrade",
|
|
26
|
-
description: "Upgrades your installation of repokit to the latest stable version",
|
|
27
|
-
args: [],
|
|
28
|
-
}),
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
pub fn static_execute(&self) {
|
|
33
|
-
Logger::info("Upgrading installation");
|
|
34
|
-
let handle = SpinnerBuilder::new()
|
|
35
|
-
.spinner(&BOUNCING_BALL)
|
|
36
|
-
.text(" Installing")
|
|
37
|
-
.start();
|
|
38
|
-
RepoKitRuntime::with_runtime(|runtime| {
|
|
39
|
-
Executor::exec(
|
|
40
|
-
format!("{} @repokit/core@latest", runtime.node.install_command).as_str(),
|
|
41
|
-
|cmd| cmd.current_dir(&runtime.git.root),
|
|
42
|
-
)
|
|
43
|
-
});
|
|
44
|
-
handle.done();
|
|
45
|
-
Logger::info("Upgrade Complete!");
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
impl InternalExecutable for UpgradeRepoKit {
|
|
50
|
-
fn run(&self, _: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
51
|
-
self.static_execute();
|
|
52
|
-
if let Some(new_version) = RepoKitRuntime::with_runtime(|runtime| {
|
|
53
|
-
runtime
|
|
54
|
-
.caches
|
|
55
|
-
.version_cache
|
|
56
|
-
.refresh_installed_version(&runtime.files)
|
|
57
|
-
}) {
|
|
58
|
-
Logger::info(
|
|
59
|
-
format!(
|
|
60
|
-
"The currently installed version is {}",
|
|
61
|
-
Logger::with_theme(|theme| theme.highlight(&new_version))
|
|
62
|
-
)
|
|
63
|
-
.as_str(),
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
fn get_definition(&self) -> &InternalExecutableDefinition {
|
|
69
|
-
&self.definition
|
|
70
|
-
}
|
|
71
|
-
}
|