Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": ">=7.3",
"php": ">=7.3||^8.0",
"symfony/event-dispatcher": "^4.0"

},
Expand Down
4 changes: 2 additions & 2 deletions src/Console/src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ public function section($name): Section
return $this->root->get($this->root->getName().' '.$name);
}

public function run(?array $argv = null): void
public function run(?array $argv = null): int
{
if ($argv === null) {
global $argv;
$argv[0] = $this->root->getName();
}

$this->executor->run($this->root, $argv);
return $this->executor->run($this->root, $argv);
}

public function getRootSection(): Section
Expand Down
14 changes: 7 additions & 7 deletions src/Console/src/Application/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getActionCollection(): ActionCollection
return $this->actions;
}

public function run(Section $section, $argv = []): void
public function run(Section $section, $argv = []): int
{
$this->argv = $argv;

Expand All @@ -94,18 +94,18 @@ public function run(Section $section, $argv = []): void

if ($this->matchedSection === null || $this->matchedInput === null) {
$this->invalidUsage($argv);
return;
return 1;
}

if ($this->beforeAction()->isActionPrevented()) {
return;
return 0;
}

if (($action = $this->matchedSection->getAction()) === null) {
return;
return 0;
Copy link

@andytson-inviqa andytson-inviqa Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do other clis do when executing a section without the command? I'd have thought it was a 1 to signify it's not a command?

Copy link
Author

@dantleech dantleech Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git and composer return 1. not sure when this condition gets invoked though ws config asd asd returns 1 (invalidUsage)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but yeah, the above 2 should probably be non-zero

}

$this->invokeAction($action);
return $this->invokeAction($action);
}

public function visit(Section $section): bool
Expand Down Expand Up @@ -193,12 +193,12 @@ private function beforeAction(): BeforeActionEvent
return $event;
}

private function invokeAction($action)
private function invokeAction($action): int
{
if (!is_callable($action)) {
$action = $this->actions->get($action);
}

$action($this->matchedInput);
return $action($this->matchedInput) ?? 0;
}
}
4 changes: 2 additions & 2 deletions src/Console/tests/Test/Usage/Parser/UsageParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function an_argument_is_defined_as_an_alpha_numeric_string_between_angle_
{
$result = usage('<environment>', 'development');

$this->assertIsArray($result);
self::assertIsArray($result);
$this->assertTrue(count($result) == 1);
}

Expand Down Expand Up @@ -331,4 +331,4 @@ public function passed_options_must_be_part_of_usage_definition()
$result = usage('[-hv] foo bar', '--unknown foo bar');
$this->assertFalse($result);
}
}
}
2 changes: 1 addition & 1 deletion src/FSM/tests/Test/Runner/BacktrackingRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ public function it_must_end_on_a_terminal_state_to_return_result()
$this->assertEquals(['S3', 'S5'], $this->fsm->input(['t1', 't2']));
$this->assertEquals(false, $this->fsm->input(['t1']));
}
}
}
2 changes: 1 addition & 1 deletion src/FSM/tests/Test/Runner/SequenceRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ public function it_must_end_on_a_terminal_state_to_return_result()
$this->assertEquals(['S2', 'S4'], $this->fsm->input(['t1', 't3']));
$this->assertEquals(false, $this->fsm->input(['t1']));
}
}
}