blib/lib/HPC/Runner/Command/new.pm untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 79 CC 3 SCAR 13.9
CC
3
Cov
0%
execute_command
12.0
execute
2.0
gen_project_yml
2.0
CRAP 4.0
1 package HPC::Runner::Command::new;
2  
3 use MooseX::App::Command;
4 use namespace::autoclean;
5  
6 use IPC::Cmd qw[can_run];
7 use File::Basename;
8 use Cwd;
9 use File::Path qw(make_path remove_tree);
10 use YAML::XS;
11 use File::Spec;
12 use File::Slurp;
13  
14 extends 'HPC::Runner::Command';
15 with 'MooseX::App::Role::Log4perl';
16  
17 command_short_description 'Create a new project';
18 command_long_description
19 'This creates a new project, initializes git and directory structure.';
20  
21 =head1 HPC::Runner::Command::new
22  
23 Create a new project using
24 hpcrunner.pl new
25  
26 =head2 Command Line Options
27  
28 =cut
29  
30 option 'project' => (
31 is => 'rw',
32 isa => 'Str',
33 documentation => 'Project name for your analysis project.',
34 required => 1,
35 predicate => 'has_project',
36 cmd_aliases => ['p'],
37 );
38  
39 =head2 Subroutines
40  
41 =head3 execute_command
42  
43 Execute short commands
44  
45 =cut
46  
47 sub execute_command {
48 my ( $self, $cmd, $info ) = @_;
49 my $buffer = "";
50  
51 if (
52 scalar IPC::Cmd::run(
53 command => $cmd,
54 verbose => 0,
55 buffer => \$buffer
56 )
57 )
58 {
59 $self->log->info("$info: $buffer\n") if $info;
60 }
61 else {
62 $self->log->warn("Something went wrong with the cmd: $cmd!\n");
63 }
64 }
65  
66 sub execute {
67 my $self = shift;
68  
69 my $project = $self->project;
70  
71 ###$DB::single=2;
72 make_path( File::Spec->catdir($self->project , "conf") );
73 make_path( File::Spec->catdir($self->project , "script") );
74 make_path( File::Spec->catdir($self->project , "data") );
75 make_path( File::Spec->catdir($self->project , "hpc-runner") );
76  
77 chdir $self->project;
78 $self->gen_project_yml;
79 $self->gen_gitignore;
80  
81 $self->log->info(
82 "By default ./data and ./hpcrunner are added to your git ignore.");
83  
84 $self->log->info("Setup complete!");
85 }
86  
87 sub gen_project_yml {
88 my ($self) = @_;
89  
90 my $hash = {
91 ProjectName => $self->project,
92 TopDir => getcwd(),
93 LogDir => File::Spec->catdir(cwd() , "hpc-runner", "logs"),
94 BlogDir => File::Spec->catdir(cwd() , "hpc-runner", "www", "hexo")
95 };
96  
97 write_file('.project.yml', Dump $hash);
98  
99 $self->log->info("Project: ".$self->project." Initialized...");
100 }
101  
102 sub gen_gitignore {
103 my $self = shift;
104  
105 $self->execute_command( "git init",
106 "Git repo successfully initialized : " );
107  
108 write_file('.gitignore', "data\nhpc-runner");
109  
110 $self->execute_command( "git add .gitignore", "Added .gitignore..." );
111 }
112  
113 __PACKAGE__->meta()->make_immutable();
114  
115 1;