Skip to content

Commit

Permalink
Merge pull request #17 from alexkunde/fix-split
Browse files Browse the repository at this point in the history
Fix pipeline/split function
  • Loading branch information
gwbres authored Jul 19, 2023
2 parents 3f579b2 + b13e369 commit 21326c9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
45 changes: 23 additions & 22 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
name: Rust

on:
push:
branches: [ main ]
workflow_dispatch:
pull_request:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

push:
branches: [ main ]
jobs:
build:
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup
uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
toolchain: stable
override: true
components: rustfmt, clippy
- name: Build
run: cargo build
- name: Test
run: cargo test -- --nocapture
- name: Build (all features)
run: cargo build --all-features
- name: Test (all features)
run: cargo test --all-features -- --nocapture
- name: Coding style
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.rustup
/usr/local/cargo
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install Rust
run: rustup update stable
- name: Run rustfmt
run: cargo fmt --all -- --check
- name: Run clippy
run: cargo clippy --all -- -D warnings
- uses: taiki-e/install-action@nextest
- name: Cargo Test
run: cargo nextest run --all-features --no-capture --no-fail-fast
20 changes: 11 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub struct Unit {
pub name: String,
/// Unit type
pub utype: Type,
/// Optionnal unit description
/// Optional unit description
pub description: Option<String>,
/// Current state
pub state: State,
Expand Down Expand Up @@ -406,20 +406,22 @@ impl Unit {
let next = lines.next().unwrap();
let (_, rem) = next.split_at(3);
let mut items = rem.split_ascii_whitespace();
let name = items.next().unwrap().trim();
let name_raw = items.next().unwrap().trim();
if let Some(delim) = items.next() {
if delim.trim().eq("-") {
// --> description string is provided
let items: Vec<_> = items.collect();
u.description = Some(itertools::join(&items, " "));
}
}
let items: Vec<_> = name.split_terminator('.').collect();
let name = items[0];

let (name, utype_raw) = name_raw
.rsplit_once('.')
.expect("Unit is missing a Type, this should not happen!");
// `type` is deduced from .extension
u.utype = Type::from_str(items[1].trim()).unwrap();
let mut docs: Vec<Doc> = Vec::with_capacity(3);
u.utype = match Type::from_str(utype_raw) {
Ok(t) => t,
Err(e) => panic!("For {:?} -> {e}", name_raw),
};
let mut is_doc = false;
for line in lines {
let line = line.trim_start();
Expand Down Expand Up @@ -453,7 +455,7 @@ impl Unit {
} else if let Some(line) = line.strip_prefix("Docs: ") {
is_doc = true;
if let Ok(doc) = Doc::from_str(line) {
docs.push(doc)
u.docs.get_or_insert_with(Vec::new).push(doc);
}
} else if let Some(line) = line.strip_prefix("What: ") {
// mountpoint infos
Expand Down Expand Up @@ -495,7 +497,7 @@ impl Unit {
if is_doc {
let line = line.trim_start();
if let Ok(doc) = Doc::from_str(line) {
docs.push(doc)
u.docs.get_or_insert_with(Vec::new).push(doc);
}
}
}
Expand Down

0 comments on commit 21326c9

Please sign in to comment.