App-Cme

 view release on metacpan or  search on metacpan

lib/App/Cme/Command/edit.pm  view on Meta::CPAN

#
# This file is part of App-Cme
#
# This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>.
#
# This is free software, licensed under:
#
#   The GNU Lesser General Public License, Version 2.1, February 1999
#
# ABSTRACT: Edit the configuration of an application

package App::Cme::Command::edit ;
$App::Cme::Command::edit::VERSION = '1.047';
use strict;
use warnings;
use 5.10.1;

use App::Cme -command ;

use base qw/App::Cme::Common/;

use Config::Model::ObjTreeScanner;

sub validate_args {
    my ($self, $opt, $args) = @_;
    $self->check_unknown_args($args);
    $self->process_args($opt,$args);
    return;
}

sub opt_spec {
    my ( $class, $app ) = @_;
    return (
        [ "ui|if=s"     => "user interface type. Either tk, curses, shell" ],
        [ "backup:s"  => "Create a backup of configuration files before saving." ],
        [ "open-item=s" => "open a specific item of the configuration" ],
        $class->cme_global_options,
    );
}

sub usage_desc {
  my ($self) = @_;
  my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
  return "$desc [application] [ file ] [ -ui tk|curses|shell ] [ -open-item xxx ] ";
}

sub description {
    my ($self) = @_;
    return $self->get_documentation;
}
sub execute {
    my ($self, $opt, $args) = @_;

    my ($model, $inst, $root) = $self->init_cme($opt,$args);

    my $has_tk =  eval { require Config::Model::TkUI; 1; };

    my $has_curses = eval { require Config::Model::CursesUI; 1; };

    my $ui_type = $opt->{ui};

    if ( not defined $ui_type ) {
        if ($has_tk) {
            $ui_type = 'tk';
        }
        elsif ($has_curses) {
            warn "You should install Config::Model::TkUI for a ", "more friendly user interface\n";
            $ui_type = 'curses';
        }
        else {
            warn "You should install Config::Model::TkUI or ",
                "Config::Model::CursesUI ",
                "for a more friendly user interface\n";
            $ui_type = 'shell';
        }
    }

    $root->deep_check;

    if ( $ui_type eq 'shell' ) {
        require Config::Model::TermUI;
        $self->run_shell_ui('Config::Model::TermUI', $inst) ;
    }
    elsif ( $ui_type eq 'curses' ) {



( run in 0.737 second using v1.01-cache-2.11-cpan-39bf76dae61 )