line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of App-Cme |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software, licensed under: |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# The GNU Lesser General Public License, Version 2.1, February 1999 |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# ABSTRACT: Edit the configuration of an application |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$App::Cme::Command::edit::VERSION = '1.038'; |
13
|
|
|
|
|
|
|
use strict; |
14
|
1
|
|
|
1
|
|
720
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
15
|
1
|
|
|
1
|
|
4
|
use 5.10.1; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
16
|
1
|
|
|
1
|
|
9
|
|
|
1
|
|
|
|
|
2
|
|
17
|
|
|
|
|
|
|
use App::Cme -command ; |
18
|
1
|
|
|
1
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
19
|
|
|
|
|
|
|
use base qw/App::Cme::Common/; |
20
|
1
|
|
|
1
|
|
298
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
21
|
|
|
|
|
|
|
use Config::Model::ObjTreeScanner; |
22
|
1
|
|
|
1
|
|
5
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
499
|
|
23
|
|
|
|
|
|
|
my ($self, $opt, $args) = @_; |
24
|
|
|
|
|
|
|
$self->check_unknown_args($args); |
25
|
0
|
|
|
0
|
1
|
|
$self->process_args($opt,$args); |
26
|
0
|
|
|
|
|
|
return; |
27
|
0
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my ( $class, $app ) = @_; |
30
|
|
|
|
|
|
|
return ( |
31
|
|
|
|
|
|
|
[ "ui|if=s" => "user interface type. Either tk, curses, shell" ], |
32
|
0
|
|
|
0
|
1
|
|
[ "backup:s" => "Create a backup of configuration files before saving." ], |
33
|
|
|
|
|
|
|
[ "open-item=s" => "open a specific item of the configuration" ], |
34
|
0
|
|
|
|
|
|
$class->cme_global_options, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my ($self) = @_; |
39
|
|
|
|
|
|
|
my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o" |
40
|
|
|
|
|
|
|
return "$desc [application] [ file ] [ -ui tk|curses|shell ] [ -open-item xxx ] "; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
0
|
1
|
|
|
43
|
0
|
|
|
|
|
|
my ($self) = @_; |
44
|
0
|
|
|
|
|
|
return $self->get_documentation; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
my ($self, $opt, $args) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
0
|
1
|
|
my ($model, $inst, $root) = $self->init_cme($opt,$args); |
49
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $has_tk = eval { require Config::Model::TkUI; 1; }; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
0
|
1
|
|
my $has_curses = eval { require Config::Model::CursesUI; 1; }; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $ui_type = $opt->{ui}; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
if ( not defined $ui_type ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
if ($has_tk) { |
58
|
0
|
|
|
|
|
|
$ui_type = 'tk'; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
elsif ($has_curses) { |
61
|
|
|
|
|
|
|
warn "You should install Config::Model::TkUI for a ", "more friendly user interface\n"; |
62
|
0
|
0
|
|
|
|
|
$ui_type = 'curses'; |
63
|
0
|
0
|
|
|
|
|
} |
|
|
0
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
else { |
65
|
|
|
|
|
|
|
warn "You should install Config::Model::TkUI or ", |
66
|
|
|
|
|
|
|
"Config::Model::CursesUI ", |
67
|
0
|
|
|
|
|
|
"for a more friendly user interface\n"; |
68
|
0
|
|
|
|
|
|
$ui_type = 'shell'; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$root->deep_check; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
if ( $ui_type eq 'shell' ) { |
75
|
|
|
|
|
|
|
require Config::Model::TermUI; |
76
|
|
|
|
|
|
|
$self->run_shell_ui('Config::Model::TermUI', $inst) ; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
elsif ( $ui_type eq 'curses' ) { |
79
|
|
|
|
|
|
|
die "cannot run curses interface: ", |
80
|
0
|
0
|
|
|
|
|
"Config::Model::CursesUI is not installed, please use shell or simple UI\n" |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
unless $has_curses; |
82
|
0
|
|
|
|
|
|
my $err_file = '/tmp/cme-error.log'; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
print "In case of error, check $err_file\n"; |
85
|
0
|
0
|
|
|
|
|
|
86
|
|
|
|
|
|
|
open( my $fh, ">", $err_file ) || die "Can't open $err_file: $!\n"; |
87
|
|
|
|
|
|
|
open(STDERR, ">&", $fh)|| die "Can't open STDERR:$!\n"; |
88
|
0
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $dialog = Config::Model::CursesUI->new(); |
90
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# engage in user interaction |
92
|
0
|
0
|
|
|
|
|
$dialog->start($model); |
93
|
0
|
0
|
|
|
|
|
|
94
|
|
|
|
|
|
|
close($fh); |
95
|
0
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
elsif ( $ui_type eq 'tk' ) { |
97
|
|
|
|
|
|
|
die "cannot run Tk interface: Config::Model::TkUI is not installed, please use curses or shell or simple ui\n" |
98
|
0
|
|
|
|
|
|
unless $has_tk; |
99
|
|
|
|
|
|
|
$self ->run_tk_ui ( $inst, $opt); |
100
|
0
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else { |
102
|
|
|
|
|
|
|
die "Unsupported user interface: $ui_type\n"; |
103
|
0
|
0
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
return; |
105
|
0
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
0
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
=pod |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=encoding UTF-8 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 NAME |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
App::Cme::Command::edit - Edit the configuration of an application |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 VERSION |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
version 1.038 |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SYNOPSIS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# edit dpkg config with GUI (requires Config::Model::Dpkg) |
125
|
|
|
|
|
|
|
cme edit dpkg |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# force usage of simple shell like interface |
128
|
|
|
|
|
|
|
cme edit dpkg-copyright --ui shell |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# edit /etc/sshd_config (requires Config::Model::OpenSsh) |
131
|
|
|
|
|
|
|
sudo cme edit sshd |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# edit ~/.ssh/config (requires Config::Model::OpenSsh) |
134
|
|
|
|
|
|
|
cme edit ssh |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# edit a file (file name specification is mandatory here) |
137
|
|
|
|
|
|
|
cme edit multistrap my.conf |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 DESCRIPTION |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Edit a configuration. By default, a Tk GUI will be opened if C<Config::Model::TkUI> is |
142
|
|
|
|
|
|
|
installed. You can choose another user interface with the C<-ui> option: |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=over |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
C<tk>: provides a Tk graphical interface (If C<Config::Model::TkUI> is |
149
|
|
|
|
|
|
|
installed). |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
C<curses>: provides a curses user interface (If |
154
|
|
|
|
|
|
|
L<Config::Model::CursesUI> is installed). |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
C<shell>: provides a shell like interface. See L<Config::Model::TermUI> |
159
|
|
|
|
|
|
|
for details. This is equivalent to running C<cme shell> command. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 Common options |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
See L<cme/"Global Options">. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 options |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item -open-item |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Open a specific item of the configuration when opening the editor |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=back |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 SEE ALSO |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
L<cme> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 AUTHOR |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Dominique Dumont |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This is free software, licensed under: |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
The GNU Lesser General Public License, Version 2.1, February 1999 |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |