permafrost-dev / ray-cli
通过命令行发送数据到 Ray
Requires
- php: ^7.4|^8.0
- ext-curl: *
- ext-json: *
- spatie/ray: ^1.7
- symfony/console: ^5.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- permafrost-dev/phpcsfixer-preset: ^1.5
- phpunit/phpunit: ^9.5
README
此包提供了与 Ray 应用程序(由 Spatie 提供)交互的命令行界面。
支持的 PHP 版本: 7.4
,8.0
。
安装
您可以使用 composer 安装此包
composer require permafrost-dev/ray-cli --dev
在 发布页面 上还有一个可下载的 phar
可执行文件。使用 phar
的主要优势是您无需将包安装到您的项目中。
如果您下载了一个 phar
,请将示例中的 vendor/bin/ray
替换为 phar
的文件名,例如:
vendor/bin/ray 'test message' --green --large
将变为
ray-1.6.0.phar 'test message' --green --large
注意:一些用户可能需要使用 chmod
将 phar 设置为可执行。例如: chmod +x ray-1.6.0.phar
用法
向 Ray 发送数据就像调用 ray
脚本并提供一个参数一样简单,该参数可以是字符串或文件名
vendor/bin/ray 'hello world'
您还可以提供一个 JSON 字符串,Ray 将为您格式化它
vendor/bin/ray '{"message": "hello world"}'
您也可以传递一个有效的文件名而不是字符串。将发送文件的内容,并自动检测 JSON。
vendor/bin/ray "testfile.json" -c green vendor/bin/ray "readme.txt"
您甚至可以传递一个有效的 URL - 它将被下载并发送到 Ray,并自动检测 JSON。
vendor/bin/ray "https://github.com/permafrost-dev/ray-cli" -c green vendor/bin/ray "https://api.github.com/repos/permafrost-dev/ray-cli"
可用选项
ray
脚本提供了一些标志,用于向 Ray 发送额外的有效负载
--update-check
参数: none
默认值: false
描述:检查 ray-cli
的更新版本。如果指定,则忽略所有其他标志。
示例
vendor/bin/ray --update-check
--exec
参数: none
默认值: false
描述:将参数视为脚本或可执行文件,执行它,并将输出发送到 Ray。支持的脚本解释器为 PHP
、Python
和 NodeJS
。如果文件是可执行的,例如二进制文件或 .sh
脚本,它也将被执行。将自动检测 JSON 内容。
示例
# refresh the display of app.log every 5 seconds vendor/bin/ray --exec "random.sh" vendor/bin/ray --exec "random-number.php"
--refresh
参数: integer
或 decimal
默认值: none
描述:每 N 秒刷新 Ray 中的有效负载显示,其中 N 是一个整数(例如,10
)或小数(例如,7.5
)。如果指定了文件,它将每 N 秒重新读取一次;如果指定了 URL,它将每 N 秒重新检索一次。
示例
# refresh the display of app.log every 5 seconds vendor/bin/ray --refresh=5 "storage/logs/app.log" # ...or refresh every 2.5 seconds vendor/bin/ray --refresh=2.5 "storage/logs/app.log"
--color
或 -c
参数: string
默认值: none
描述:与数据一起发送 "color" 有效负载。
示例
vendor/bin/ray -c red "hello world"
--large
或 --lg
参数: none
默认值: false
描述:将有效负载作为大号文本发送。
示例
vendor/bin/ray --large "hello world" vendor/bin/ray --lg "hello world"
--small
or --sm
参数: none
默认值: false
描述:将有效负载作为小号文本发送。
示例
vendor/bin/ray --small "hello world" vendor/bin/ray --sm "hello world"
--size
或 -S
参数: string
默认值: normal
可能值: large
、lg
、small
、sm
、normal
描述:发送指定文本大小的有效负载。参见 --large
和 --small
。 注意,虽然包含在内以供完整性,但指定 normal
是不必要的,因为它是默认文本大小。
示例
vendor/bin/ray -S sm "hello world" vendor/bin/ray -S large "hello world" vendor/bin/ray --size=normal "hello world"
--label
或 -L
参数: string
默认值: none
描述:与数据一起发送 "label" 有效负载。仅在发送纯文本(非 JSON 和非定界)时才有效。
示例
vendor/bin/ray -L "my label" "hello world"
--notify
或 -N
参数: none
默认值: false
描述:发送一个“通知”有效负载,导致Ray显示操作系统通知而不是在其窗口中记录数据。
示例
vendor/bin/ray -N "hello from ray-cli"
--csv
参数: none
默认值: false
描述:将有效负载数据视为以逗号分隔的值列表,并将使用 explode()
的数据发送为结果值的数组。
示例
vendor/bin/ray --csv "one,two,three"
--delimiter
或 -D
参数: string
默认值: none
描述:将有效负载数据视为由提供的分隔符字符串分隔的值列表,并将使用 explode()
的数据发送为结果值的数组。
示例
vendor/bin/ray -D '|' "one|two|three"
--json
或 -j
参数: none
默认值: false
描述:强制将有效负载数据视为JSON字符串。注意,在大多数情况下,此标志是不必要的,因为JSON字符串会自动检测。
示例
vendor/bin/ray --json '["one","two","three"]'
--stdin
参数: none
默认值: false
描述:从标准输入读取有效负载数据,而不是作为命令行参数。注意,可以使用破折号 ("-"
) 来指定有效负载数据,而不是指定 --stdin
标志。
示例
echo "hello world" | vendor/bin/ray --stdin echo "hello world" | vendor/bin/ray -
--raw
参数: none
默认值: false
描述:强制对有效负载数据进行预处理并显示未经渲染的原始内容。数据被处理以编码HTML实体、空格,并将换行符转换为 <br>
标签 (这是为了显示HTML源代码)。
示例
cat sample.html | vendor/bin/ray --stdin --raw
vendor/bin/ray --raw sample.html
--screen
或 -s
参数: string
默认值: none
描述:在Ray中创建一个新的屏幕,参数为新屏幕的“名称”。传递空字符串或字符串值 "-"
将导致屏幕无名称 (与调用 ray()->clearScreen()
的效果相同)。将 --screen
或 -s
作为命令行上的最后一个参数与提供屏幕名称 "-"
相同。
示例
# create a screen named "debug #1": vendor/bin/ray -s 'debug #1' "hello world" vendor/bin/ray --screen='debug #1' "hello world" # create a screen with no name: vendor/bin/ray -s- "hello world" vendor/bin/ray --screen=- "hello world" vendor/bin/ray --screen= "hello world" vendor/bin/ray "hello world" -s # create a named screen without sending data: vendor/bin/ray --screen="my screen 2" vendor/bin/ray -s "my screen 3"
--clear
或 -C
参数: none
默认值: none
示例:描述:导致Ray清除屏幕 (实际上是在创建一个没有名称的新屏幕)。 如果同时提供 --screen
和 --clear
,则 --clear
优先。
示例
# clear the screen and send some data: vendor/bin/ray -C "hello world" vendor/bin/ray --clear "hello world" # clear the screen without sending any data: vendor/bin/ray -C vendor/bin/ray --clear
--clear-all
参数: none
默认值: none
描述:导致Ray清除所有屏幕。
示例
vendor/bin/ray --clear-all
--image
或 -i
参数: none
默认值: none
描述:将有效负载视为图像。有效负载必须是URL或现有文件名。
示例
vendor/bin/ray --image https://static.permafrost.dev/images/ray-cli/ray-cli-logo-01.png vendor/bin/ray -i my-image-file.png
--blue
,--gray
,--green
,--orange
,--purple
,--red
参数: none
默认值: false
描述:以指定的颜色发送有效负载。是 --color=N
标志的别名。
示例
vendor/bin/ray --red "hello world" vendor/bin/ray --orange "hello world" # only the first flag is used when multiple flags are provided. # sent as green: vendor/bin/ray --green --red --blue "hello world"
--bg-blue
,--bg-gray
,--bg-green
,--bg-orange
,--bg-purple
,--bg-red
参数: none
默认值: false
描述:以指定的背景颜色发送有效负载。
示例
vendor/bin/ray --bg-purple --large "hello world"
示例
使用蓝色标记将JSON文件的内容发送到Ray
cat my-data.json | vendor/bin/ray --stdin -c blue vendor/bin/ray 'my-data.json' --blue
以小文本、红色标记和名为“my data”的新屏幕发送 test.json
的内容
vendor/bin/ray --screen='my data' --red --small 'test.json'
测试
此包使用PHPUnit进行单元测试。要运行测试套件,请运行
./vendor/bin/phpunit
变更日志
请参阅 变更日志 了解最近更改的详细信息。
许可证
MIT许可证(MIT)。有关更多信息,请参阅 许可证文件。