@repokit/core 1.0.4 → 1.1.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/README.md CHANGED
@@ -14,7 +14,7 @@ The Repokit CLI exists as a living source of documentation and knowledge - growi
14
14
 
15
15
  If you do not have node.js setup in your repository, you'll first want to install node.js.
16
16
 
17
- [NVM is a populat posix compliant installer](https://github.com/nvm-sh/nvm)
17
+ [NVM is a popular posix compliant installer](https://github.com/nvm-sh/nvm)
18
18
 
19
19
  Once installed, you can run the following in the root of your repository
20
20
 
@@ -13,6 +13,7 @@ export interface IRepoKitCommand {
13
13
  export interface ICommand {
14
14
  command: string;
15
15
  description: string;
16
+ args?: Record<string, string>;
16
17
  }
17
18
 
18
19
  export interface ILocatedCommand extends IRepoKitCommand {
@@ -2,7 +2,39 @@ use std::collections::HashMap;
2
2
 
3
3
  #[derive(Clone)]
4
4
  pub struct InternalExecutableDefinition {
5
- pub name: &'static str,
6
- pub description: &'static str,
7
- pub args: HashMap<&'static str, &'static str>,
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
  }
@@ -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.contains("new RepoKitCommand(") {
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, Command>,
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::blue_bright(command.name),
32
- Logger::gray(command.description),
31
+ Logger::blue(&command.name),
32
+ Logger::gray(&command.description),
33
33
  );
34
- Help::print_args(&command.args);
34
+ Help::log_args(&command.args, None);
35
35
  }
36
36
 
37
- pub fn log_root_command(command: &ParsedCommand) {
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::blue_bright(&command.name),
51
+ Logger::blue(&command.name),
51
52
  Logger::gray(&command.description),
52
53
  );
53
- Help::print_commands(&command.commands, Some(6));
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 print_commands(map: &HashMap<String, Command>, indentation: Option<i32>) {
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::green(format!("{}: ", name).as_str()),
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, Command>) {
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 print_args(map: &HashMap<&'static str, &'static str>) {
114
- for (name, description) in map {
115
- println!(
116
- "{}{}{}",
117
- Logger::indent(Some(6)),
118
- Logger::green(format!("{}: ", name).as_str()),
119
- Logger::gray(description),
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, Command>) -> Vec<ParsedCommand> {
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| ParsedCommand::from(name, commands.get(name).expect("known keys only")))
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::InternalExecutableDefinition,
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: HashMap::from([(
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
- .leak() as &'static str,
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::InternalExecutableDefinition,
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: HashMap::from([]),
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::InternalExecutableDefinition,
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: HashMap::from([("<name>", "The name of a registered command")]),
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::InternalExecutableDefinition,
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: HashMap::from([]),
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::InternalExecutableDefinition,
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: HashMap::from([(
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
 
@@ -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::InternalExecutableDefinition,
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: HashMap::from([(
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
- for (arg, description) in &config.args {
46
- if arg.to_lowercase().contains(query) || description.to_lowercase().contains(query) {
47
- return true;
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: &Command) -> bool {
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, Command>) {
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, Command> = HashMap::new();
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 {
@@ -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::InternalExecutableDefinition,
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: HashMap::from([]),
30
- },
31
+ args: [],
32
+ }),
31
33
  }
32
34
  }
33
35
 
@@ -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()
@@ -3,22 +3,25 @@ use std::collections::HashMap;
3
3
  use serde::Deserialize;
4
4
 
5
5
  #[derive(Debug, Deserialize, Clone)]
6
- pub struct Command {
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 ParsedCommand {
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 ParsedCommand {
19
- pub fn from(name: &str, command: &Command) -> ParsedCommand {
20
- ParsedCommand {
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, Command>,
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, Command>,
43
+ pub commands: HashMap<String, CommandDefinition>,
41
44
  }
@@ -125,17 +125,18 @@ impl RepoKit {
125
125
  )
126
126
  .as_str(),
127
127
  );
128
- Help::print_commands(&command.commands, Some(3));
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::blue_bright(&command.name)
134
+ "Listing available commands for {}\n",
135
+ Logger::blue(&command.name)
136
136
  )
137
137
  .as_str(),
138
138
  );
139
- Help::print_commands(&command.commands, Some(3))
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.4",
3
+ "version": "1.1.0",
4
4
  "description": "A knowledgebase for your repository - wrapped in a CLI",
5
5
  "keywords": [
6
6
  "cli",
@@ -20,7 +20,7 @@
20
20
  "access": "public"
21
21
  },
22
22
  "scripts": {
23
- "build:all": "yarn lint:ts && yarn lint:rust && yarn install:repokit",
23
+ "build:all": "yarn lint:ts && yarn lint:rust && yarn install:rust",
24
24
  "build:rust": "cargo build --release",
25
25
  "install:rust": "yarn build:rust && cargo install --path .",
26
26
  "lint:rust": "cargo clippy --fix --allow-dirty",