Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ t/throw.t
t/tiedhash.t
t/trace_vars.t
t/try.t
t/ttree_config.t
t/unicode.t
t/url.t
t/vars.t
Expand Down
2 changes: 1 addition & 1 deletion lib/Template/App/ttree.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ sub offer_create_a_sample_config_file {
my $RCFILE = $self->_get_rc_file();
# offer create a sample config file if it doesn't exist, unless a '-f'
# has been specified on the command line
unless (-f $RCFILE or grep(/^(-f|-h|--help)$/, @ARGV) ) {
unless (-f $RCFILE or grep(/^(-f|--file(?:=.*)?|-h|--help)$/, @ARGV) ) {
$self->emit_log("Do you want me to create a sample '.ttreerc' file for you?\n",
"(file: $RCFILE) [y/n]: ");
my $y = <STDIN>;
Expand Down
45 changes: 45 additions & 0 deletions t/ttree_config.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/perl
#
# Test that ttree does not prompt for config file creation when
# --file=FILE or --file FILE is specified on the command line (GH #282).
#

use strict;
use warnings;
use Test::More;
use File::Temp qw(tempdir);

eval "use AppConfig";
plan skip_all => "AppConfig not installed" if $@;

plan tests => 4;

use_ok('Template::App::ttree');

my $tmpdir = tempdir(CLEANUP => 1);

# Ensure no default rc file exists so the prompt logic would trigger
local $ENV{HOME} = $tmpdir;

my $ttree = Template::App::ttree->new;
isa_ok($ttree, 'Template::App::ttree');

# With -f, the prompt should be suppressed
{
local @ARGV = ('-f', "$tmpdir/myconfig");
my $prompted = 0;
no warnings 'redefine';
local *Template::App::ttree::emit_log = sub { $prompted = 1 };
$ttree->offer_create_a_sample_config_file();
ok(!$prompted, '-f suppresses config file prompt');
}

# With --file=FILE, the prompt should also be suppressed (GH #282)
{
local @ARGV = ("--file=$tmpdir/myconfig");
my $prompted = 0;
no warnings 'redefine';
local *Template::App::ttree::emit_log = sub { $prompted = 1 };
$ttree->offer_create_a_sample_config_file();
ok(!$prompted, '--file=FILE suppresses config file prompt');
}
Loading