From 7feb9f78e51c22ffa8c1cec5fed033e689949576 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 9 Sep 2022 10:05:22 +0300 Subject: chore: use unwrap_or instead of more complicated structure Sponsored-by: author --- src/cloudinit.rs | 4 ++-- src/spec.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cloudinit.rs b/src/cloudinit.rs index c748dd1..9d14538 100644 --- a/src/cloudinit.rs +++ b/src/cloudinit.rs @@ -175,8 +175,8 @@ impl Metadata { } fn cleanup_document(doc: &str) -> String { - let doc = doc.strip_prefix("---\n").or(Some(doc)).unwrap(); - let doc = doc.strip_suffix('\n').or(Some(doc)).unwrap(); + let doc = doc.strip_prefix("---\n").unwrap_or(doc); + let doc = doc.strip_suffix('\n').unwrap_or(doc); doc.to_string() } diff --git a/src/spec.rs b/src/spec.rs index 332bf94..5f5a28e 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -387,7 +387,7 @@ fn ssh_keys(filenames: &[PathBuf]) -> Result, SpecificationError> { let key = std::fs::read(&filename).map_err(|e| SpecificationError::SshKeyRead(filename, e))?; let key = String::from_utf8(key)?; - let key = key.strip_suffix('\n').or(Some(&key)).unwrap(); + let key = key.strip_suffix('\n').unwrap_or(&key); keys.push(key.to_string()); } Ok(keys) -- cgit v1.2.1 From 2a78d1909ba7ccecad6e07a4b988eb77d4385359 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 9 Sep 2022 10:09:40 +0300 Subject: fix: use new Subplot external metadata Sponsored-by: author --- check | 31 ++++++++++++++----------------- vmadm.md | 16 ---------------- vmadm.subplot | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 33 deletions(-) create mode 100644 vmadm.subplot diff --git a/check b/check index 0e48419..a6018e3 100755 --- a/check +++ b/check @@ -5,27 +5,24 @@ set -eu hideok=chronic -if [ "$#" -gt 0 ] -then - case "$1" in +if [ "$#" -gt 0 ]; then + case "$1" in verbose | -v | --verbose) - hideok= - shift - ;; - esac + hideok= + shift + ;; + esac fi -if [ "$#" = 0 ] -then - echo "MUST give path to base image for testing" 1>&2 - exit 1 +if [ "$#" = 0 ]; then + echo "MUST give path to base image for testing" 1>&2 + exit 1 fi base_image="$1" shift -got_cargo_cmd() -{ - cargo --list | grep " $1 " > /dev/null +got_cargo_cmd() { + cargo --list | grep " $1 " >/dev/null } $hideok cargo build --all-targets @@ -33,10 +30,10 @@ got_cargo_cmd clippy && cargo clippy -q got_cargo_cmd fmt && $hideok cargo fmt -- --check $hideok cargo test -subplot docgen vmadm.md -o vmadm.html -subplot docgen vmadm.md -o vmadm.pdf +subplot docgen vmadm.subplot -o vmadm.html +subplot docgen vmadm.subplot -o vmadm.pdf -subplot codegen vmadm.md -o test.py +subplot codegen vmadm.subplot -o test.py rm -f test.log $hideok python3 test.py --log test.log --env="BASE_IMAGE=$base_image" "$@" diff --git a/vmadm.md b/vmadm.md index e24e0db..7d5ae96 100644 --- a/vmadm.md +++ b/vmadm.md @@ -1,19 +1,3 @@ ---- -title: "vmadm – virtual machine administration" -author: "Lars Wirzenius" -bindings: - - subplot/vmadm.yaml - - lib/files.yaml - - lib/runcmd.yaml -impls: - python: - - subplot/vmadm.py - - lib/files.py - - lib/runcmd.py -classes: -- json -... - # Data files for scenarios This section has some data files used by scenarios. diff --git a/vmadm.subplot b/vmadm.subplot new file mode 100644 index 0000000..ef76a9e --- /dev/null +++ b/vmadm.subplot @@ -0,0 +1,15 @@ +title: "vmadm – virtual machine administration" +author: "Lars Wirzenius" +markdowns: + - vmadm.md +bindings: + - subplot/vmadm.yaml + - lib/files.yaml + - lib/runcmd.yaml +impls: + python: + - subplot/vmadm.py + - lib/files.py + - lib/runcmd.py +classes: +- json -- cgit v1.2.1