MCPcopy Create free account
hub / github.com/dfinity/ic-repl / run

Method run

src/command.rs:55–224  ·  view source on GitHub ↗
(self, helper: &mut MyHelper)

Source from the content-addressed store, hash-verified

53
54impl Command {
55 pub fn run(self, helper: &mut MyHelper) -> anyhow::Result<()> {
56 match self {
57 Command::Import(id, canister_id, did) => {
58 if let Some(did) = &did {
59 let path = resolve_path(&helper.base_path, did);
60 let info = did_to_canister_info(did, FileSource::Path(&path), None)?;
61 helper.canister_map.borrow_mut().0.insert(canister_id, info);
62 }
63 // TODO decide if it's a Service instead
64 helper.env.0.insert(id, IDLValue::Principal(canister_id));
65 }
66 Command::Let(id, val) => {
67 let is_call = val.is_call();
68 let v = val.eval(helper)?;
69 bind_value(helper, id, v, is_call, false);
70 }
71 Command::Func { name, args, body } => {
72 helper.func_env.0.insert(name, (args, body));
73 }
74 Command::Assert(op, left, right) => {
75 let left = left.eval(helper)?;
76 let right = right.eval(helper)?;
77 match op {
78 BinOp::Equal => assert_eq!(left, right),
79 BinOp::SubEqual => {
80 if let (IDLValue::Text(left), IDLValue::Text(right)) = (&left, &right) {
81 assert!(left.contains(right));
82 } else {
83 let l_ty = left.value_ty();
84 let r_ty = right.value_ty();
85 let env = TypeEnv::new();
86 if let Ok(left) = left.annotate_type(false, &env, &r_ty) {
87 assert_eq!(left, right);
88 } else if let Ok(right) = right.annotate_type(false, &env, &l_ty) {
89 assert_eq!(left, right);
90 } else {
91 assert_eq!(left, right);
92 }
93 }
94 }
95 BinOp::NotEqual => assert_ne!(left, right),
96 }
97 }
98 Command::Config(conf) => {
99 if conf.ends_with(".toml") {
100 let path = resolve_path(&helper.base_path, &conf);
101 let conf = std::fs::read_to_string(path)?;
102 helper.config = conf.parse::<Configs>()?;
103 } else {
104 helper.config = conf.parse::<Configs>()?;
105 }
106 }
107 Command::Show(val) => {
108 let is_call = val.is_call();
109 let time = Instant::now();
110 let v = val.eval(helper)?;
111 let duration = time.elapsed();
112 bind_value(helper, "_".to_string(), v, is_call, true);

Callers 3

replFunction · 0.80
evalMethod · 0.80
apply_funcFunction · 0.80

Calls 7

resolve_pathFunction · 0.85
did_to_canister_infoFunction · 0.85
bind_valueFunction · 0.85
error2Function · 0.85
is_callMethod · 0.80
evalMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected