-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchoreographer
executable file
·117 lines (104 loc) · 3.87 KB
/
choreographer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
use lib 'local/lib/perl5'; # TODO: Convert to local::lib
use lib 'lib';
use strict;
use warnings;
use Dancer::Choreographer;
use Term::ANSIColor qw(:constants);
use Getopt::Long;
Getopt::Long::Configure('bundling');
my $json_file = '';
GetOptions( 'json|f=s', \$json_file )
or die("Error in command line arguments\n");
setting_the_stage();
# Get json string;
my $json = '';
# If file exists slurp
if (-f $json_file) {
open my $json_fh, "<", $json_file or die $!;
{
local $/;
$json = <$json_fh>;
}
close $json_fh;
} else {
$json = $json_file;
}
my $msgs = choreograph($json);
if (@{ $msgs->{'success'} }) {
#print "Success:\n";
foreach my $msg ( @{ $msgs->{'success'} } ) {
print GREEN, $msg."\n", RESET;
}
}
if (@{ $msgs->{'errors'} }) {
#print "Errors:\n";
foreach my $msg ( @{ $msgs->{'errors'} } ) {
print RED, $msg."\n", RESET;
}
}
if (@{ $msgs->{'output'} }) {
print "Output:\n";
foreach my $msg ( @{ $msgs->{'output'} } ) {
print $msg."\n";
}
}
1;
__END__
Example Json
'[
{
"models" : [
{
"readable_name" : "Test",
"write_file" : 1,
"table_name" : "test",
"attributes" : [
{
"inline" : 0,
"options" : [],
"order" : "0",
"static_label" : 0,
"type" : "text",
"label" : "Test",
"max_length" : 32,
"mandatory" : 0
},
{
"inline" : 0,
"options" : [],
"order" : "1",
"static_label" : 0,
"type" : "email",
"label" : "Email",
"max_length" : 64,
"mandatory" : 0
},
{
"inline" : 0,
"options" : [
"Male",
"Female"
],
"order" : "2",
"static_label" : 0,
"type" : "radio",
"label" : "Gender",
"mandatory" : 1,
"max_length" : 16
}
],
"overlay" : ""
}
],
"settings" : {
"app_path" : "/Users/seanzellmer/Apps/Demo/",
"app_name" : "Demo",
"write_files" : 1,
"overwrite" : 1,
"module_only": 1
}
}
]'