| 1 | package App::Ordo::Command::Cd; | ||
| 2 | use Moo; | ||
| 3 | extends 'App::Ordo::Command::Base'; | ||
| 4 | use feature qw(say); | ||
| 5 | use utf8; | ||
| 6 | use open ':std', ':utf8'; | ||
| 7 | use App::Ordo qw($CURRENT_PATH); | ||
| 8 | use Term::ANSIColor qw(colored); | ||
| 9 | #use Text::Table::Tiny 1.02 qw(generate_table); | ||
| 10 | |||
| 11 | sub name { "cd" } | ||
| 12 | sub summary { "Change current cluster" } | ||
| 13 | sub usage { "<path>" } | ||
| 14 | |||
| 15 | # No options — pure positional | ||
| 16 | sub option_spec { {} } | ||
| 17 | |||
| 18 | sub execute { | ||
| 19 | my ($self, $opt, $target) = @_; | ||
| 20 | |||
| 21 | my $res = $self->api->call('change_cluster', { name => $target }); | ||
| 22 | |||
| 23 | if ($res->{success}) { | ||
| 24 | $App::Ordo::CURRENT_PATH = $res->{path}; | ||
| 25 | } else { | ||
| 26 | say colored(["bold red"], "Cannot cd to '$target': " . ($res->{message} || 'not found')); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | 1; |