Skip to content

Commit f5387b7

Browse files
committed
Apply rust formatting.
Very minor adjustments in rustfmt.toml
1 parent a42ede8 commit f5387b7

File tree

9 files changed

+370
-236
lines changed

9 files changed

+370
-236
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[rust]": {
3+
"editor.defaultFormatter": "rust-lang.rust-analyzer",
4+
"editor.formatOnSave": true
5+
}
6+
}

rustfmt.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
match_block_trailing_comma = true
2+
max_width = 119

src/init.rs

Lines changed: 148 additions & 73 deletions
Large diffs are not rendered by default.

src/inspect.rs

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::fmt::{self, Display};
21
use std::error::Error;
2+
use std::fmt::{self, Display};
33
use std::io::{self, Read, Write};
44

55
use ascii_table::{Align, AsciiTable};
@@ -29,7 +29,7 @@ impl Display for InspectDisplay {
2929
Self::Table => write!(f, "table"),
3030
Self::Json => write!(f, "json"),
3131
Self::None => write!(f, "none"),
32-
}
32+
}
3333
}
3434
}
3535

@@ -98,10 +98,10 @@ impl Displayable for registry::Collection {
9898
fn display_table(&self) {
9999
let mut table = AsciiTable::default();
100100
let data = [
101-
[ "Name", self.source_information.name.as_ref()],
102-
[ "Maintainer", self.source_information.maintainer.as_ref()],
103-
[ "Contact", self.source_information.contact.as_ref()],
104-
[ "Repository", self.source_information.repository.as_ref()],
101+
["Name", self.source_information.name.as_ref()],
102+
["Maintainer", self.source_information.maintainer.as_ref()],
103+
["Contact", self.source_information.contact.as_ref()],
104+
["Repository", self.source_information.repository.as_ref()],
105105
["OCI Reference", self.source_information.oci_reference.as_ref()],
106106
];
107107

@@ -123,24 +123,31 @@ impl Displayable for registry::Feature {
123123
data.maybe_push("Documentation URL", self.documentation_url.as_ref());
124124
data.maybe_push("License URL", self.license_url.as_ref());
125125
data.maybe_push("Keywords", self.keywords.as_ref().map(comma_join));
126-
data.many_push("Options", self.options.as_ref().map(|options| {
127-
options.iter()
128-
.map(|(key, value)| format!("name={key}, {value}"))
129-
.collect::<Vec<String>>()
130-
}));
131-
data.many_push("Container ENV", self.container_env.as_ref().map(|container_env| {
132-
container_env.iter()
133-
.map(|(key, value)| format!("{key}={value}"))
134-
.collect::<Vec<String>>()
135-
}));
126+
data.many_push(
127+
"Options",
128+
self.options.as_ref().map(|options| {
129+
options
130+
.iter()
131+
.map(|(key, value)| format!("name={key}, {value}"))
132+
.collect::<Vec<String>>()
133+
}),
134+
);
135+
data.many_push(
136+
"Container ENV",
137+
self.container_env.as_ref().map(|container_env| {
138+
container_env
139+
.iter()
140+
.map(|(key, value)| format!("{key}={value}"))
141+
.collect::<Vec<String>>()
142+
}),
143+
);
136144
data.maybe_push("Privileged", self.privileged);
137145
data.maybe_push("Init", self.init);
138146
data.maybe_push("Cap Add", self.cap_add.as_ref().map(comma_join));
139147
data.maybe_push("Security Opt", self.security_opt.as_ref().map(comma_join));
140148
data.maybe_push("Entrypoint", self.entrypoint.as_ref());
141149

142-
let vscode_extensions =
143-
self.customizations.as_ref()
150+
let vscode_extensions = (self.customizations.as_ref())
144151
.and_then(|customizations| customizations.vscode_extensions())
145152
.as_ref()
146153
.map(comma_join);
@@ -176,11 +183,15 @@ impl Displayable for registry::Template {
176183
data.maybe_push("Description", self.description.as_ref());
177184
data.maybe_push("Documentation URL", self.documentation_url.as_ref());
178185
data.maybe_push("License URL", self.license_url.as_ref());
179-
data.many_push("Options", self.options.as_ref().map(|options| {
180-
options.iter()
181-
.map(|(key, value)| format!("name={key}, {value}"))
182-
.collect::<Vec<String>>()
183-
}));
186+
data.many_push(
187+
"Options",
188+
self.options.as_ref().map(|options| {
189+
options
190+
.iter()
191+
.map(|(key, value)| format!("name={key}, {value}"))
192+
.collect::<Vec<String>>()
193+
}),
194+
);
184195
data.maybe_push("Platforms", self.platforms.as_ref().map(comma_join));
185196
data.maybe_push("Publisher", self.publisher.as_ref());
186197
data.maybe_push("Keywords", self.keywords.as_ref().map(comma_join));
@@ -252,7 +263,10 @@ fn display_install_sh(oci_ref: &OciReference) -> Result<(), Box<dyn Error>> {
252263
}
253264
}
254265

255-
Err(io::Error::new(io::ErrorKind::NotFound, "The install.sh script was not found in the archive"))?
266+
Err(io::Error::new(
267+
io::ErrorKind::NotFound,
268+
"The install.sh script was not found in the archive",
269+
))?
256270
}
257271

258272
pub fn inspect(
@@ -262,7 +276,7 @@ pub fn inspect(
262276
display_as,
263277
install_sh,
264278
show_files,
265-
}: InspectArgs
279+
}: InspectArgs,
266280
) -> Result<(), Box<dyn Error>> {
267281
log::debug!("inspect");
268282

@@ -311,7 +325,10 @@ pub fn inspect(
311325
Ok(())
312326
},
313327
(None, None, None) => Err(io::Error::new(io::ErrorKind::NotFound, "No match found for given id.")),
314-
_ => Err(io::Error::new(io::ErrorKind::Unsupported, "Multiple results found for given id.")),
328+
_ => Err(io::Error::new(
329+
io::ErrorKind::Unsupported,
330+
"Multiple results found for given id.",
331+
)),
315332
}?;
316333

317334
log::debug!("inspect: done");

src/list.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ fn collection_templates_and_features(oci_reference: &str, collection: &Collectio
2727
let templates = collection.templates.iter().map(search::SearchResult::from);
2828
features.chain(templates)
2929
};
30-
let data: Vec<[String; 5]> =
31-
search_results.enumerate().map(|(i, r)| {
32-
let description =
33-
r.description.as_ref()
30+
let data: Vec<[String; 5]> = search_results
31+
.enumerate()
32+
.map(|(i, r)| {
33+
let description = r
34+
.description
35+
.as_ref()
3436
.and_then(|d| d.lines().next())
3537
.unwrap_or_default();
3638
[
@@ -63,15 +65,17 @@ fn overview_collections(index: &DevcontainerIndex) {
6365
table.column(2).set_header("Features").set_align(Align::Right);
6466
table.column(3).set_header("Templates").set_align(Align::Right);
6567

66-
let result: Vec<[String; 4]> =
67-
index.collections()
68+
let result: Vec<[String; 4]> = index
69+
.collections()
6870
.iter()
69-
.map(|collection| [
70-
collection.source_information.name.to_string(),
71-
collection.source_information.oci_reference.to_string(),
72-
format!("{}", collection.features.len()),
73-
format!("{}", collection.templates.len()),
74-
])
71+
.map(|collection| {
72+
[
73+
collection.source_information.name.to_string(),
74+
collection.source_information.oci_reference.to_string(),
75+
format!("{}", collection.features.len()),
76+
format!("{}", collection.templates.len()),
77+
]
78+
})
7579
.collect();
7680

7781
table.print(result);
@@ -81,11 +85,9 @@ pub fn list(index: &DevcontainerIndex, ListArgs { collection_id }: ListArgs) {
8185
log::debug!("list");
8286

8387
match collection_id {
84-
Some(oci_reference) => {
85-
match index.get_collection(&oci_reference) {
86-
Some(collection) => collection_templates_and_features(&oci_reference, collection),
87-
None => println!("No collection found by the given OCI Reference: {}", oci_reference),
88-
}
88+
Some(oci_reference) => match index.get_collection(&oci_reference) {
89+
Some(collection) => collection_templates_and_features(&oci_reference, collection),
90+
None => println!("No collection found by the given OCI Reference: {}", oci_reference),
8991
},
9092
None => overview_collections(index),
9193
}

src/main.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,43 @@ enum Commands {
4141
#[cfg(feature = "completions")]
4242
Completions { shell: Shell },
4343
/// Create new devcontainer.
44-
Init (init::InitArgs),
44+
Init(init::InitArgs),
4545
/// Display details of a specific feature, template, or collection.
46-
Inspect (inspect::InspectArgs),
46+
Inspect(inspect::InspectArgs),
4747
/// Overview of collections.
48-
List (list::ListArgs),
48+
List(list::ListArgs),
4949
/// Text search the `id`, `keywords`, and `description` fields of templates or features.
50-
Search (search::SearchArgs),
50+
Search(search::SearchArgs),
5151
}
5252

5353
fn program_name() -> io::Result<String> {
5454
log::debug!("program_name");
5555
let exe = env::current_exe()?;
56-
exe
57-
.file_name()
58-
.and_then(OsStr::to_str)
59-
.map(String::from)
60-
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Executable not a file path"))
56+
exe.file_name()
57+
.and_then(OsStr::to_str)
58+
.map(String::from)
59+
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Executable not a file path"))
6160
}
6261

6362
fn data_directory<P: AsRef<Path>>(namespace: P) -> io::Result<PathBuf> {
6463
log::debug!("data_directory");
6564
if let Some(path) = dirs::data_dir() {
6665
Ok(path.join(namespace))
6766
} else {
68-
Err(io::Error::new(io::ErrorKind::InvalidData, "Unable to determine a valid data directory"))
67+
Err(io::Error::new(
68+
io::ErrorKind::InvalidData,
69+
"Unable to determine a valid data directory",
70+
))
6971
}
7072
}
7173

7274
fn main() -> Result<(), Box<dyn Error>> {
7375
let args = Args::parse();
7476

7577
env_logger::Builder::new()
76-
.filter_level(args.verbose.log_level_filter())
77-
.format_timestamp_millis()
78-
.init();
78+
.filter_level(args.verbose.log_level_filter())
79+
.format_timestamp_millis()
80+
.init();
7981

8082
let prog_name = program_name()?;
8183
let data_dir = data_directory(&prog_name)?;
@@ -94,7 +96,10 @@ fn main() -> Result<(), Box<dyn Error>> {
9496
if let Some(command) = args.command {
9597
if !index_file.exists() {
9698
// suggested user action
97-
log::error!("Missing devcontainer-index.json.\n\n\tRun `{} --pull-index`.\n", prog_name);
99+
log::error!(
100+
"Missing devcontainer-index.json.\n\n\tRun `{} --pull-index`.\n",
101+
prog_name
102+
);
98103
}
99104

100105
let index = registry::read_devcontainer_index(index_file)?;
@@ -104,10 +109,10 @@ fn main() -> Result<(), Box<dyn Error>> {
104109
Commands::Completions { shell } => {
105110
generate(shell, &mut Args::command_for_update(), &prog_name, &mut io::stdout());
106111
},
107-
Commands::Init (args) => init::init(&index, args)?,
108-
Commands::Inspect (args) => inspect::inspect(&index, args)?,
109-
Commands::List (args) => list::list(&index, args),
110-
Commands::Search (args) => search::search(&index, args)?,
112+
Commands::Init(args) => init::init(&index, args)?,
113+
Commands::Inspect(args) => inspect::inspect(&index, args)?,
114+
Commands::List(args) => list::list(&index, args),
115+
Commands::Search(args) => search::search(&index, args)?,
111116
};
112117
}
113118

src/oci_ref.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ impl FromStr for OciReference {
2121
type Err = ocipkg::error::Error;
2222

2323
fn from_str(name: &str) -> Result<Self, Self::Err> {
24-
ImageName::parse(name)
25-
.map(OciReference)
24+
ImageName::parse(name).map(OciReference)
2625
}
2726
}
2827

2928
#[cfg(test)]
3029
mod tests {
31-
use ocipkg::error::Result;
3230
use super::OciReference;
31+
use ocipkg::error::Result;
3332

3433
#[test]
3534
fn test_parse() -> Result<()> {

0 commit comments

Comments
 (0)