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: Dump the configuration of an application |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package App::Cme::Command::dump ; |
13
|
|
|
|
|
|
|
$App::Cme::Command::dump::VERSION = '1.036'; |
14
|
1
|
|
|
1
|
|
830
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
15
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
25
|
|
16
|
1
|
|
|
1
|
|
11
|
use 5.10.1; |
|
1
|
|
|
|
|
3
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
7
|
use App::Cme -command ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
351
|
use base qw/App::Cme::Common/; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
105
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
8
|
use Config::Model::ObjTreeScanner; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
23
|
1
|
|
|
1
|
|
582
|
use YAML; |
|
1
|
|
|
|
|
7894
|
|
|
1
|
|
|
|
|
65
|
|
24
|
1
|
|
|
1
|
|
7
|
use JSON; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
25
|
1
|
|
|
1
|
|
156
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
639
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub validate_args { |
28
|
0
|
|
|
0
|
1
|
|
my ($self, $opt, $args) = @_; |
29
|
0
|
|
|
|
|
|
$self->check_unknown_args($args); |
30
|
0
|
|
|
|
|
|
$opt->{quiet} = 1; # don't want to mess up yaml output |
31
|
0
|
|
|
|
|
|
$self->process_args($opt,$args); |
32
|
0
|
|
|
|
|
|
return; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub opt_spec { |
36
|
0
|
|
|
0
|
1
|
|
my ( $class, $app ) = @_; |
37
|
|
|
|
|
|
|
return ( |
38
|
|
|
|
|
|
|
[ |
39
|
0
|
|
|
|
|
|
"dumptype=s" => "Dump all values (full) or only customized values", |
40
|
|
|
|
|
|
|
{ |
41
|
|
|
|
|
|
|
regex => qr/^(?:full|custom|non_upstream_default)$/, |
42
|
|
|
|
|
|
|
default => 'custom' |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
], |
45
|
|
|
|
|
|
|
[ |
46
|
|
|
|
|
|
|
"format=s" => "dump using specified format (yaml json perl cml)", |
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
regex => qr/^(?:json|ya?ml|perl|cml|cds)$/i, |
49
|
|
|
|
|
|
|
default => 'yaml' |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
], |
52
|
|
|
|
|
|
|
$class->cme_global_options, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub usage_desc { |
57
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
58
|
0
|
|
|
|
|
|
my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o" |
59
|
0
|
|
|
|
|
|
return "$desc [application] [ config_file ] [ -dumptype full|custom ] [ path ]"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub description { |
63
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
64
|
0
|
|
|
|
|
|
return $self->get_documentation; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub execute { |
68
|
0
|
|
|
0
|
1
|
|
my ($self, $opt, $args) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my ($model, $inst, $root) = $self->init_cme($opt,$args); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $target_node = $root->grab(step => "@$args", type => 'node'); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $dump_string; |
75
|
0
|
|
|
|
|
|
my $format = $opt->{format}; |
76
|
0
|
|
0
|
|
|
|
my $mode = $opt->{dumptype} || 'custom'; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if ($format =~ /cml|cds/i) { |
79
|
0
|
|
|
|
|
|
$dump_string = $target_node->dump_tree( mode => $mode ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
0
|
|
|
|
|
|
my $perl_data = $target_node->dump_as_data( |
83
|
|
|
|
|
|
|
ordered_hash_as_list => 0, |
84
|
|
|
|
|
|
|
mode => $mode |
85
|
|
|
|
|
|
|
); |
86
|
0
|
0
|
|
|
|
|
$dump_string |
|
|
0
|
|
|
|
|
|
87
|
|
|
|
|
|
|
= $format =~ /ya?ml/i ? Dump($perl_data) |
88
|
|
|
|
|
|
|
: $format =~ /json/i ? encode_json($perl_data) |
89
|
|
|
|
|
|
|
: Dumper($perl_data) ; # Perl data structure |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
print $dump_string ; |
92
|
0
|
|
|
|
|
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=pod |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=encoding UTF-8 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 NAME |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
App::Cme::Command::dump - Dump the configuration of an application |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 VERSION |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
version 1.036 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SYNOPSIS |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# dump ~/.ssh/config in cme syntax |
114
|
|
|
|
|
|
|
# (this example requires Config::Model::OpenSsh) |
115
|
|
|
|
|
|
|
$ cme dump -format cml ssh |
116
|
|
|
|
|
|
|
Host:"*" - |
117
|
|
|
|
|
|
|
Host:"*.debian.org" |
118
|
|
|
|
|
|
|
User=dod - |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 DESCRIPTION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Dump configuration content on STDOUT with YAML format. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
By default, dump only custom values, i.e. different from application |
125
|
|
|
|
|
|
|
built-in values or model default values. You can use the C<-dumptype> option for |
126
|
|
|
|
|
|
|
other types of dump: |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
-dumptype [ full | custom | non_upstream_default ] |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Choose to dump every values (full), or only customized values (default) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
C<non_upstream_default> is like C<full> mode, but value identical with |
133
|
|
|
|
|
|
|
application default are omitted. But this should seldom happen. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
By default, dump in yaml format. This can be changed in C<json>, |
136
|
|
|
|
|
|
|
C<perl>, C<cml> (aka L<Config::Model::Loader> format, C<cds> is also |
137
|
|
|
|
|
|
|
accepted) with C<-format> option. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 Common options |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
See L<cme/"Global Options">. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 SEE ALSO |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L<cme> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 AUTHOR |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Dominique Dumont |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This is free software, licensed under: |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The GNU Lesser General Public License, Version 2.1, February 1999 |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |