Show More
@@ -286,9 +286,9 b' dependencies = [' | |||
|
286 | 286 | |
|
287 | 287 | [[package]] |
|
288 | 288 | name = "format-bytes" |
|
289 |
version = "0.2. |
|
|
289 | version = "0.2.1" | |
|
290 | 290 | source = "registry+https://github.com/rust-lang/crates.io-index" |
|
291 | checksum = "cc35f5e45d6b31053cea13078ffc6fa52fa8617aa54b7ac2011720d9c009e04f" | |
|
291 | checksum = "8030ff4b04f0ca1c612d6fe49f2fc18caf56fb01497cb370b41cfd36d89b3b06" | |
|
292 | 292 | dependencies = [ |
|
293 | 293 | "format-bytes-macros", |
|
294 | 294 | "proc-macro-hack", |
@@ -14,6 +14,7 b' use crate::config::layer::{' | |||
|
14 | 14 | }; |
|
15 | 15 | use crate::utils::files::get_bytes_from_os_str; |
|
16 | 16 | use format_bytes::{write_bytes, DisplayBytes}; |
|
17 | use std::collections::HashSet; | |
|
17 | 18 | use std::env; |
|
18 | 19 | use std::path::{Path, PathBuf}; |
|
19 | 20 | use std::str; |
@@ -361,6 +362,14 b' impl Config {' | |||
|
361 | 362 | None |
|
362 | 363 | } |
|
363 | 364 | |
|
365 | /// Return all keys defined for the given section | |
|
366 | pub fn get_section_keys(&self, section: &[u8]) -> HashSet<&[u8]> { | |
|
367 | self.layers | |
|
368 | .iter() | |
|
369 | .flat_map(|layer| layer.iter_keys(section)) | |
|
370 | .collect() | |
|
371 | } | |
|
372 | ||
|
364 | 373 | /// Get raw values bytes from all layers (even untrusted ones) in order |
|
365 | 374 | /// of precedence. |
|
366 | 375 | #[cfg(test)] |
@@ -115,6 +115,14 b' impl ConfigLayer {' | |||
|
115 | 115 | Some(self.sections.get(section)?.get(item)?) |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | /// Returns the keys defined in the given section | |
|
119 | pub fn iter_keys(&self, section: &[u8]) -> impl Iterator<Item = &[u8]> { | |
|
120 | self.sections | |
|
121 | .get(section) | |
|
122 | .into_iter() | |
|
123 | .flat_map(|section| section.keys().map(|vec| &**vec)) | |
|
124 | } | |
|
125 | ||
|
118 | 126 | pub fn is_empty(&self) -> bool { |
|
119 | 127 | self.sections.is_empty() |
|
120 | 128 | } |
@@ -17,5 +17,5 b' log = "0.4.11"' | |||
|
17 | 17 | micro-timer = "0.3.1" |
|
18 | 18 | regex = "1.3.9" |
|
19 | 19 | env_logger = "0.7.1" |
|
20 |
format-bytes = "0.2. |
|
|
20 | format-bytes = "0.2.1" | |
|
21 | 21 | users = "0.11.0" |
@@ -4,7 +4,7 b' use clap::App;' | |||
|
4 | 4 | use clap::AppSettings; |
|
5 | 5 | use clap::Arg; |
|
6 | 6 | use clap::ArgMatches; |
|
7 | use format_bytes::format_bytes; | |
|
7 | use format_bytes::{format_bytes, join}; | |
|
8 | 8 | use hg::config::Config; |
|
9 | 9 | use hg::repo::{Repo, RepoError}; |
|
10 | 10 | use hg::utils::files::{get_bytes_from_os_str, get_path_from_bytes}; |
@@ -25,6 +25,8 b' fn main_with_result(' | |||
|
25 | 25 | repo: Result<&Repo, &NoRepoInCwdError>, |
|
26 | 26 | config: &Config, |
|
27 | 27 | ) -> Result<(), CommandError> { |
|
28 | check_extensions(config)?; | |
|
29 | ||
|
28 | 30 | let app = App::new("rhg") |
|
29 | 31 | .global_setting(AppSettings::AllowInvalidUtf8) |
|
30 | 32 | .setting(AppSettings::SubcommandRequired) |
@@ -352,3 +354,25 b' impl OnUnsupported {' | |||
|
352 | 354 | } |
|
353 | 355 | } |
|
354 | 356 | } |
|
357 | ||
|
358 | const SUPPORTED_EXTENSIONS: &[&[u8]] = &[b"blackbox", b"share"]; | |
|
359 | ||
|
360 | fn check_extensions(config: &Config) -> Result<(), CommandError> { | |
|
361 | let enabled = config.get_section_keys(b"extensions"); | |
|
362 | ||
|
363 | let mut unsupported = enabled; | |
|
364 | for supported in SUPPORTED_EXTENSIONS { | |
|
365 | unsupported.remove(supported); | |
|
366 | } | |
|
367 | ||
|
368 | if unsupported.is_empty() { | |
|
369 | Ok(()) | |
|
370 | } else { | |
|
371 | Err(CommandError::UnsupportedFeature { | |
|
372 | message: format_bytes!( | |
|
373 | b"extensions: {}", | |
|
374 | join(unsupported, b", ") | |
|
375 | ), | |
|
376 | }) | |
|
377 | } | |
|
378 | } |
General Comments 0
You need to be logged in to leave comments.
Login now