Changeset 1654

Show
Ignore:
Timestamp:
09/02/06 22:04:43
Author:
miyagawa
Message:

plugin-start: call vcs tool like svn/svk after creating the template files

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/tools/plugin-start.pl

    r1423 r1654  
    33use warnings; 
    44 
     5use Config; 
    56use FindBin; 
    67use ExtUtils::MakeMaker; 
     
    3940    my $template = YAML::Load(join '', <DATA>); 
    4041    my $vars = { module => $module, plugin => $plugin, path => $path, author => $author }; 
    41     write_file("lib/Plagger/Plugin/$path.pm", $template->{plugin}, $vars); 
    42     write_file("deps/$plugin.yaml", $template->{deps}, $vars); 
    43     write_file("t/plugins/$plugin/base.t", $template->{test}, $vars); 
     42 
     43    my @files; 
     44    push @files, write_file("lib/Plagger/Plugin/$path.pm", $template->{plugin}, $vars); 
     45    push @files, write_file("deps/$plugin.yaml", $template->{deps}, $vars); 
     46    push @files, write_file("t/plugins/$plugin/base.t", $template->{test}, $vars); 
     47 
     48    if (my $vcs = version_control()) { 
     49        my $ans = prompt("$vcs add newly created files? [Yn]", 'y'); 
     50        if ($ans =~ /[Yy]/) { 
     51            system($vcs, 'add', @files); 
     52        } 
     53    } 
    4454} 
    4555 
     
    6575    print $out $content; 
    6676    close $out; 
     77 
     78    return $path; 
     79} 
     80 
     81sub version_control { 
     82    return 'svk' if check_command('svk', 'svk info', qr/Checkout Path/); 
     83    return 'svn' if -e ".svn/entries"; 
     84    return; 
     85} 
     86 
     87sub check_command { 
     88    my($bin, $command, $re) = @_; 
     89    return unless grep { -e File::Spec->catfile($_, $bin) } split /$Config::Config{path_sep}/, $ENV{PATH}; 
     90 
     91    my $res = qx($command); 
     92    defined $res && $res =~ $re; 
    6793} 
    6894