Skip to content

Commit

Permalink
clean up example code
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFerraro committed Apr 12, 2024
1 parent 55f0a5a commit 2ca52f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
10 changes: 2 additions & 8 deletions packages/cadmium/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,23 @@ fn main() {
plane_id: top_plane_id.clone(),
plane: Plane::top(),
});
let set_name = el.append(Operation::SetPlaneName {
plane_id: top_plane_id.clone(),
name: "Top2".to_string(),
});
let new_extrusion = el.append(Operation::CreateExtrusion {
nonce: "b".to_string(),
});
let set_ext_name = el.append(Operation::SetExtrusionName {
extrusion_id: new_extrusion.clone(),
name: "Extrusion1".to_string(),
});

// Rewind to an earlier commit
el.checkout(top_plane_id.clone());
el.append(Operation::SetPlaneName {
plane_id: top_plane_id.clone(),
name: "Bottom".to_string(),
});
el.cherry_pick(set_plane);
el.cherry_pick(set_name);
el.cherry_pick(new_extrusion);
el.cherry_pick(set_ext_name);
// let new_extrusion = el.append(Operation::CreateExtrusion {
// nonce: "c".to_string(),
// });

el.git_log()
}
Expand Down
33 changes: 17 additions & 16 deletions packages/cadmium/src/oplog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl Commit {

impl std::fmt::Display for Commit {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}: {}", &self.id[..8], self.operation)
write!(f, "{}: {}", &self.id[..6], self.operation)
}
}

Expand Down Expand Up @@ -418,43 +418,44 @@ impl Operation {
}

pub fn pretty_print(&self) -> String {
let num_chars = 6;
match self {
Operation::Create { nonce } => format!("Create: {}", nonce),
Operation::Describe {
description,
commit,
} => format!(
"Describe: {} '{}'",
commit.to_owned()[..10].to_string(),
commit.to_owned()[..num_chars].to_string(),
description
),
Operation::Alias { original, new } => {
format!(
"Alias: from {} to {}",
original.to_owned()[..10].to_string(),
new.to_owned()[..10].to_string()
original.to_owned()[..num_chars].to_string(),
new.to_owned()[..num_chars].to_string()
)
}
Operation::CreatePlane { nonce } => format!("CreatePlane: {}", nonce),
Operation::SetPlaneName { plane_id, name } => {
format!(
"SetPlaneName: {} '{}'",
plane_id.to_owned()[..10].to_string(),
plane_id.to_owned()[..num_chars].to_string(),
name
)
}
Operation::SetPlane { plane_id, plane } => {
format!(
"SetPlane: {}",
plane_id.to_owned()[..10].to_string(),
plane_id.to_owned()[..num_chars].to_string(),
// plane
)
}
Operation::CreateSketch { nonce } => format!("CreateSketch: {}", nonce),
Operation::SetSketchName { sketch_id, name } => {
format!(
"SetSketchName: {} '{}'",
sketch_id.to_owned()[..10].to_string(),
sketch_id.to_owned()[..num_chars].to_string(),
name
)
}
Expand All @@ -464,8 +465,8 @@ impl Operation {
} => {
format!(
"SetSketchPlane: {} {}",
sketch_id.to_owned()[..10].to_string(),
plane_id.to_owned()[..10].to_string()
sketch_id.to_owned()[..num_chars].to_string(),
plane_id.to_owned()[..num_chars].to_string()
)
}
Operation::AddSketchRectangle {
Expand All @@ -476,7 +477,7 @@ impl Operation {
height,
} => format!(
"AddSketchRectangle: {} ({}, {}) {}x{}",
sketch_id.to_owned()[..10].to_string(),
sketch_id.to_owned()[..num_chars].to_string(),
x,
y,
width,
Expand All @@ -489,7 +490,7 @@ impl Operation {
radius,
} => format!(
"AddSketchCircle: {} ({}, {}) r={}",
sketch_id.to_owned()[..10].to_string(),
sketch_id.to_owned()[..num_chars].to_string(),
x,
y,
radius
Expand All @@ -498,7 +499,7 @@ impl Operation {
Operation::SetExtrusionName { extrusion_id, name } => {
format!(
"SetExtrusionName: {} '{}'",
extrusion_id.to_owned()[..10].to_string(),
extrusion_id.to_owned()[..num_chars].to_string(),
name
)
}
Expand All @@ -508,8 +509,8 @@ impl Operation {
} => {
format!(
"SetExtrusionSketch: {} {}",
extrusion_id.to_owned()[..10].to_string(),
sketch_id.to_owned()[..10].to_string()
extrusion_id.to_owned()[..num_chars].to_string(),
sketch_id.to_owned()[..num_chars].to_string()
)
}
Operation::SetExtrusionClicks {
Expand All @@ -522,7 +523,7 @@ impl Operation {
}
format!(
"SetExtrusionClicks: {} {}",
extrusion_id.to_owned()[..10].to_string(),
extrusion_id.to_owned()[..num_chars].to_string(),
click_str
)
}
Expand All @@ -532,7 +533,7 @@ impl Operation {
} => {
format!(
"SetExtrusionDepth: {} {}",
extrusion_id.to_owned()[..10].to_string(),
extrusion_id.to_owned()[..num_chars].to_string(),
depth
)
}
Expand Down

0 comments on commit 2ca52f6

Please sign in to comment.