如何使用寻呼机制作ruby命令行应用程序?

qhw*_*hwa 6 ruby command-line pager

我正在使用Ruby制作命令行工具.它会在屏幕上打印很多文字.目前,我正在使用shell pipeline(may_app | more)这样做.但我认为最好有一个默认的寻呼机.

它就像你执行时看到的那样git log.可以使用禁用寻呼机git --nopager log.

我做了很多谷歌工作并找到了一个宝石:hirb,但它似乎有点矫枉过正.

经过多次尝试,我目前正在使用shell包装器来执行此操作:

#!/bin/bash

# xray.rb is the core script
# doing the main logic and will
# output many rows of text on 
# screen
XRAY=$HOME/fdev-xray/xray.rb

if [ "--nopager" == "$1" ]; then
    shift
    $XRAY $*
else
    $XRAY $* | more
fi
Run Code Online (Sandbox Code Playgroud)

有用.但有更好的方法吗?

zed*_*xff 3

你做得对。但最好more从环境变量中获取寻呼机$PAGER(如果有)。

例如,有些人喜欢less这样做,而另一些人则在此变量中设置了他们最喜欢的解析器选项。more