fix(host,cli): enforce console capability and label call --json output
- host: `打印` checks the console capability at the execution point (pure and project modes grant it, but the boundary is now real instead of decorative). - cli: `marqdo call --json` reports "command":"call" instead of "run".
This commit is contained in:
1 parent
2f1b10d0ee
commit
fae0cd4b18
2 files changed
+11
-3
No files matched your search
@@ -485,6 +485,7 @@ pub fn execute(
|
|||||||
json: bool,
|
json: bool,
|
||||||
trace: bool,
|
trace: bool,
|
||||||
) -> i32 {
|
) -> i32 {
|
||||||
|
let command_name = if function.is_some() { "call" } else { "run" };
|
||||||
let project = match load_project(file, json) {
|
let project = match load_project(file, json) {
|
||||||
Ok(project) => project,
|
Ok(project) => project,
|
||||||
Err(code) => return code,
|
Err(code) => return code,
|
||||||
@@ -492,7 +493,7 @@ pub fn execute(
|
|||||||
if project.has_errors() {
|
if project.has_errors() {
|
||||||
if json {
|
if json {
|
||||||
output::print_json(&json!({
|
output::print_json(&json!({
|
||||||
"command": "run",
|
"command": command_name,
|
||||||
"success": false,
|
"success": false,
|
||||||
"diagnostics": output::diagnostics_json(&project.diagnostics),
|
"diagnostics": output::diagnostics_json(&project.diagnostics),
|
||||||
}));
|
}));
|
||||||
@@ -589,7 +590,7 @@ pub fn execute(
|
|||||||
Ok(outcome) => {
|
Ok(outcome) => {
|
||||||
if json {
|
if json {
|
||||||
output::print_json(&json!({
|
output::print_json(&json!({
|
||||||
"command": "run",
|
"command": command_name,
|
||||||
"success": true,
|
"success": true,
|
||||||
"value": marqdo_value::to_wire(&outcome.value),
|
"value": marqdo_value::to_wire(&outcome.value),
|
||||||
"stdout": stdout_text,
|
"stdout": stdout_text,
|
||||||
@@ -616,7 +617,7 @@ pub fn execute(
|
|||||||
Err(error) => {
|
Err(error) => {
|
||||||
if json {
|
if json {
|
||||||
output::print_json(&json!({
|
output::print_json(&json!({
|
||||||
"command": "run",
|
"command": command_name,
|
||||||
"success": false,
|
"success": false,
|
||||||
"stdout": stdout_text,
|
"stdout": stdout_text,
|
||||||
"error": runtime_error_json(&error, &project),
|
"error": runtime_error_json(&error, &project),
|
||||||
|
|||||||
@@ -254,6 +254,13 @@ impl StdHost {
|
|||||||
args: Vec<Value>,
|
args: Vec<Value>,
|
||||||
ctx: &ExecutionContext,
|
ctx: &ExecutionContext,
|
||||||
) -> Result<Value, RuntimeError> {
|
) -> Result<Value, RuntimeError> {
|
||||||
|
if !self.capabilities.console {
|
||||||
|
return Err(RuntimeError::new(
|
||||||
|
ErrorCategory::PermissionDenied,
|
||||||
|
ctx.span,
|
||||||
|
"program output (console) capability was not granted",
|
||||||
|
));
|
||||||
|
}
|
||||||
if args.len() != 1 {
|
if args.len() != 1 {
|
||||||
return Err(arity(ctx.span, "打印", 1, args.len()));
|
return Err(arity(ctx.span, "打印", 1, args.len()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user