-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2c6252
commit 0b498af
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Alfred\Workflows\ItemParam; | ||
|
||
trait HasConfig | ||
{ | ||
use HasParams; | ||
|
||
/** | ||
* The `config` object enables dynamic (and overriding) configuration of | ||
* the workflow objects connected to the output of the JSON Utility. | ||
* | ||
* The easiest way to find out which configuration fields are available | ||
* for an object is to copy the object configuration from the right-click | ||
* popup menu for the selected workflow object on the canvas. | ||
* | ||
* Only the included fields will be overridden, allowing for partial dynamic | ||
* configuration of a workflow object. | ||
* | ||
* The fields are generally self-explanatory, but if you have trouble identifying | ||
* a field, set it to a unique value in the object's configuration sheet and copy | ||
* the configuration again. You'll see the value you set. | ||
* | ||
* @param string|array $key | ||
* @param mixed $value | ||
* | ||
* @link https://www.alfredapp.com/help/workflows/utilities/json/ | ||
*/ | ||
public function config($key, $value = null): self | ||
{ | ||
if (is_array($key)) { | ||
$this->mergeParam('config', $key); | ||
return $this; | ||
} | ||
|
||
$this->mergeParam('config', [$key => $value]); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Alfred\Workflows; | ||
|
||
use Alfred\Workflows\ItemParam\HasArguments; | ||
use Alfred\Workflows\ItemParam\HasConfig; | ||
use Alfred\Workflows\ItemParam\HasVariables; | ||
|
||
class RunScript | ||
{ | ||
use HasVariables; | ||
use HasArguments; | ||
use HasConfig; | ||
|
||
public function output(bool $echo = true): string | ||
{ | ||
$json = json_encode([ | ||
'alfredworkflow' => $this->params, | ||
]); | ||
|
||
if ($echo) { | ||
echo $json; | ||
} | ||
|
||
return $json; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
it('can add variables from a run script', function () { | ||
$output = $this->workflow->setFromRunScript()->variables([ | ||
'color' => 'green', | ||
])->output(false); | ||
|
||
expect($output)->toBe(json_encode(['alfredworkflow' => ['variables' => ['color' => 'green']]])); | ||
}); | ||
|
||
it('can add an argument from a run script', function () { | ||
$output = $this->workflow->setFromRunScript()->arg('just passing through')->output(false); | ||
|
||
expect($output)->toBe(json_encode(['alfredworkflow' => ['arg' => 'just passing through']])); | ||
}); | ||
|
||
it('can add a config from a run script', function () { | ||
$output = $this->workflow->setFromRunScript()->config([ | ||
'url' => '{query}', | ||
])->output(false); | ||
|
||
expect($output)->toBe(json_encode(['alfredworkflow' => ['config' => ['url' => '{query}']]])); | ||
}); | ||
|
||
it('can add a combination from a run script', function () { | ||
$output = $this->workflow->setFromRunScript()->config([ | ||
'url' => '{query}', | ||
])->variables([ | ||
'color' => 'green', | ||
])->arg('just passing through')->output(false); | ||
|
||
expect($output)->toBe(json_encode(['alfredworkflow' => [ | ||
'config' => ['url' => '{query}'], | ||
'variables' => ['color' => 'green'], | ||
'arg' => 'just passing through', | ||
]])); | ||
}); |