コード例 #1
0
ファイル: example.php プロジェクト: thesmart/php-cli-tools
require __DIR__ . '/vendor/autoload.php';
$menu = array('out_out' => 'cli\\out Example', 'out_err' => 'cli\\err Example', 'out_line' => 'cli\\line Example', 'notify_dots' => 'cli\\notify\\Dots Example', 'notify_spinner' => 'cli\\notify\\Spinner Example', 'progress_bar' => 'cli\\progress\\Bar Example', 'table' => 'cli\\Table Example', 'colors' => 'cli\\Colors example', 'quit' => 'Quit');
$headers = array('First Name', 'Last Name', 'City', 'State');
$data = array(array('Maryam', 'Elliott', 'Elizabeth City', 'SD'), array('Jerry', 'Washington', 'Bessemer', 'ME'), array('Allegra', 'Hopkins', 'Altoona', 'ME'), array('Audrey', 'Oneil', 'Dalton', 'SK'), array('Ruth', 'Mcpherson', 'San Francisco', 'ID'), array('Odessa', 'Tate', 'Chattanooga', 'FL'), array('Violet', 'Nielsen', 'Valdosta', 'AB'), array('Summer', 'Rollins', 'Revere', 'SK'), array('Mufutau', 'Bowers', 'Scottsbluff', 'WI'), array('Grace', 'Rosario', 'Garden Grove', 'KY'), array('Amanda', 'Berry', 'La Habra', 'AZ'), array('Cassady', 'York', 'Fulton', 'BC'), array('Heather', 'Terrell', 'Statesboro', 'SC'), array('Dominic', 'Jimenez', 'West Valley City', 'ME'), array('Rhonda', 'Potter', 'Racine', 'BC'), array('Nathan', 'Velazquez', 'Cedarburg', 'BC'), array('Richard', 'Fletcher', 'Corpus Christi', 'BC'), array('Cheyenne', 'Rios', 'Broken Arrow', 'VA'), array('Velma', 'Clemons', 'Helena', 'IL'), array('Samuel', 'Berry', 'Lawrenceville', 'NU'), array('Marcia', 'Swanson', 'Fontana', 'QC'), array('Zachary', 'Silva', 'Port Washington', 'MB'), array('Hilary', 'Chambers', 'Suffolk', 'HI'), array('Idola', 'Carroll', 'West Sacramento', 'QC'), array('Kirestin', 'Stephens', 'Fitchburg', 'AB'));
function test_notify(\cli\Notify $notify, $cycle = 1000000, $sleep = null)
{
    for ($i = 0; $i <= $cycle; $i++) {
        $notify->tick();
        if ($sleep) {
            usleep($sleep);
        }
    }
    $notify->finish();
}
while (true) {
    $choice = \cli\menu($menu, null, 'Choose an example');
    \cli\line();
    switch ($choice) {
        case 'quit':
            break 2;
        case 'out_out':
            \cli\out("  \\cli\\out sends output to STDOUT\n");
            \cli\out("  It does not automatically append a new line\n");
            \cli\out("  It does accept any number of %s which are then %s to %s for formatting\n", 'arguments', 'passed', 'sprintf');
            \cli\out("  Alternatively, {:a} can use an {:b} as the second argument.\n", array('a' => 'you', 'b' => 'array'));
            break;
        case 'out_err':
            \cli\err('  \\cli\\err sends output to STDERR');
            \cli\err('  It does automatically append a new line');
            \cli\err('  It does accept any number of %s which are then %s to %s for formatting', 'arguments', 'passed', 'sprintf');
            \cli\err('  Alternatively, {:a} can use an {:b} as the second argument.', array('a' => 'you', 'b' => 'array'));
コード例 #2
0
 private function choice($choices, $question = false)
 {
     if (!$question) {
         $question = __('Choose something', 'acf-wpcli');
     }
     while (true) {
         $choice = \cli\menu($choices, null, $question);
         \cli\line();
         break;
     }
     return $choice;
 }
コード例 #3
0
 protected static function resolveTree($menu, $default = 'quit', $text = 'Your choice:')
 {
     $choice = false;
     while ($choice === false) {
         $choice = \cli\menu($menu, $default, \cli\Colors::colorize($text));
     }
     \cli\line();
     return $choice;
 }
コード例 #4
0
 protected function select_acf_field()
 {
     $field_groups = get_posts(array('numberposts' => -1, 'post_type' => 'acf', 'sort_column' => 'menu_order', 'order' => 'ASC'));
     $choices = array();
     $choices[''] = 'all';
     foreach ($field_groups as $group) {
         $choices[$group->ID] = $group->post_title;
     }
     while (true) {
         $choice = \cli\menu($choices, null, 'Pick a fieldgroup to export');
         \cli\line();
         return $choice;
         break;
     }
 }