Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add --local to config command.

Also rename project_file to local_file, so all is consistent.
  • Loading branch information...
commit 2c88ec9298cddd486dd8f5525b5e57c65b539a4f 1 parent ac99e9e
@theory authored
View
2  Changes
@@ -1,6 +1,8 @@
Revision history for Perl extension App::Sqitch
0.12
+ - Added `--local` option to `sqitch config`.
+ - Renamed `project_file()` to `--local_file()` in App::Sqitch::Config.
0.11 2012-04-27T06:44:54Z
- Implemented `init` command.
View
34 lib/App/Sqitch/Command/config.pm
@@ -16,7 +16,7 @@ our $VERSION = '0.12';
has file => (is => 'ro', lazy => 1, default => sub {
my $self = shift;
- my $meth = $self->context . '_file';
+ my $meth = ($self->context || 'local') . '_file';
return $self->sqitch->config->$meth;
});
@@ -34,8 +34,8 @@ has action => (is => 'ro', isa => enum([qw(
rename-section
remove-section
)]));
-has context => (is => 'ro', required => 1, default => 'project', isa => enum([qw(
- project
+has context => (is => 'ro', isa => maybe_type enum([qw(
+ local
user
system
)]));
@@ -44,6 +44,7 @@ has type => (is => 'ro', isa => enum([qw(int num bool bool-or-int)]));
sub options {
return qw(
file|config-file|f=s
+ local
user
system
@@ -70,7 +71,7 @@ sub configure {
my ($class, $config, $opt) = @_;
# Make sure we are accessing only one file.
- my @file = grep { $opt->{$_} } qw(user system file);
+ my @file = grep { $opt->{$_} } qw(local user system file);
$class->usage('Only one config file at a time.') if @file > 1;
# Make sure we have only one type.
@@ -94,7 +95,7 @@ sub configure {
$class->usage('Only one action at a time.') if @action > 1;
# Get the action and context.
- my $context = first { $opt->{$_} } qw(user system);
+ my $context = first { $opt->{$_} } qw(local user system);
# Make it so.
return {
@@ -272,9 +273,9 @@ sub unset_all {
sub list {
my $self = shift;
- my $config = $self->context eq 'project'
- ? $self->sqitch->config
- : $self->_file_config;
+ my $config = $self->context
+ ? $self->_file_config
+ : $self->sqitch->config;
$self->emit(scalar $config->dump) if $config;
return $self;
}
@@ -342,7 +343,7 @@ __END__
=head1 Name
-App::Sqitch::Command::config - Get and set project, user, or system Sqitch options
+App::Sqitch::Command::config - Get and set local, user, or system Sqitch options
=head1 Synopsis
@@ -437,7 +438,7 @@ The configuration file context. Must be one of:
=over
-=item * C<project>
+=item * C<local>
=item * C<user>
@@ -445,8 +446,6 @@ The configuration file context. Must be one of:
=back
-Defaults to C<project>.
-
=item C<type>
The type to cast a value to be set to or fetched as. May be one of:
@@ -561,16 +560,17 @@ Removes a section. Exits with an error if the section does not exist.
$config->list;
-Lists all of the values in the configuration. If the context is C<system> or
-C<user>, only the settings set for that context will be emitted. Otherwise,
-all settings will be listed.
+Lists all of the values in the configuration. If the context is C<local>,
+C<user>, or C<system>, only the settings set for that context will be emitted.
+Otherwise, all settings will be listed.
=head3 C<edit>
$config->edit;
Opens the context-specific configuration file in a text editor for direct
-editing. The editor is determined by L<Sqitch/editor>.
+editing. If no context is specified, the local config file will be opened. The
+editor is determined by L<Sqitch/editor>.
=head2 Instance Accessors
@@ -603,8 +603,6 @@ The Sqitch command-line client.
=item * Make exit codes the same as C<git-config>.
-=item * Implement C<--local>.
-
=back
=head1 Author
View
2  lib/App/Sqitch/Command/init.pm
@@ -41,7 +41,7 @@ sub write_config {
my $sqitch = $self->sqitch;
my $meta = $sqitch->meta;
my $config = $sqitch->config;
- my $file = $config->project_file;
+ my $file = $config->local_file;
if (-f $file) {
# Do nothing? Update config?
return $self;
View
10 lib/App/Sqitch/Config.pm
@@ -35,12 +35,12 @@ sub user_file {
return file $hd, '.sqitch', shift->confname;
}
-sub project_file {
+sub local_file {
return $ENV{SQITCH_CONFIG} if $ENV{SQITCH_CONFIG};
return file +File::Spec->curdir, shift->confname;
}
-sub dir_file { shift->project_file }
+sub dir_file { shift->local_file }
sub get_section {
my ($self, %p) = @_;
@@ -95,15 +95,15 @@ Returns the path to the user configuration file. The value returned will be
the contents of the C<$SQITCH_USER_CONFIG> environment variable, if it's
defined, or else C<~/.sqitch/sqitch.conf>.
-=head3 C<project_file>
+=head3 C<local_file>
-Returns the path to the project configuration file, which is just
+Returns the path to the local configuration file, which is just
F<./sqitch.conf>, unless C<$SQITCH_CONFIG> is set, in which case its value
will be returned.
=head3 C<dir_file>
-An alias for C<project_file()> for use by the parent class.
+An alias for C<local_file()> for use by the parent class.
=head3 C<get_section>
View
1  lib/sqitch-config-usage.pod
@@ -10,6 +10,7 @@ sqitch-config-usage - Sqitch config usage statement
Config file location
+ --local use local config file
--user use user config file
--system use system config file
--local use repository config file
View
41 lib/sqitch-config.pod
@@ -1,6 +1,6 @@
=head1 Name
-sqitch-config - Get and set project, user, or system Sqitch options
+sqitch-config - Get and set local, user, or system Sqitch options
=head1 Synopsis
@@ -36,10 +36,10 @@ form (simple integer for C<--int>, decimal number for C<--num>, a "true" or
"false" string for C<--bool>) If no type specifier is passed, no checks or
transformations are performed on the value.
-The C<file-option> can be one of C<--system>, C<--user> or C<--file>, which
-specify where the values will be read from or written to. The default is to
-assume the config file of the current project directory, F<./sqitch.conf>
-(see L<Files>).
+The C<file-option> can be one of C<--local>, C<--user>, C<--system>, or
+C<--file>, which specify where the values will be read from or written to. The
+default is to assume the local config file in the current project directory,
+for editing, and the all files merged for fetching (see L<Files>).
=begin comment
@@ -117,6 +117,16 @@ exactly one.
Like C<--get-all>, but interprets the name as a regular expression and writes
out the key names and value.
+=item C<--local>
+
+For writing options: write to the local F<./sqitch.conf> file. This is
+the default if no file option is specified.
+
+For reading options: read only from the local F<./sqitch.conf> file rather
+than from all available files.
+
+See also L<Files>.
+
=item C<--user>
For writing options: write to the user F<~/.sqitch/sqitch.conf> file rather
@@ -180,8 +190,9 @@ C<--bool> or C<--int>, as described above.
=item C<-e, --edit>
-Opens an editor to modify the specified config file; either C<--system>,
-C<--user>, or repository (default).
+Opens an editor to modify the specified config file; either C<--local>,
+C<--user>, C<--system>, or C<--file>. If none of those options is specified,
+the local file will be opened.
=back
@@ -194,7 +205,7 @@ C<sqitch config> will search for configuration options:
=item C<./sqitch.conf>
-Project-specific configuration file.
+Local, project-specific configuration file.
=item C<~/.sqitch/sqitch.conf>
@@ -212,8 +223,7 @@ System-wide configuration file.
=item C<SQITCH_CONFIG>
-Take the project configuration from the given file instead of
-C<./sqitch.conf>.
+Take the local configuration from the given file instead of C<./sqitch.conf>.
=item C<SQITCH_USER_CONFIG>
@@ -306,11 +316,12 @@ To add a new setting without altering any of the existing ones, use:
=head1 Configuration File
The sqitch configuration file contains a number of variables that affect the
-sqitch command's behavior. The F<./sqitch.conf> file in each project is used
-to store the configuration for that project, and F<$HOME/.sqitch/sqitch.conf>
-is used to store a per-user configuration as fallback values for the
-F<./sqitch.conf> file. The file F<$(prefix>/etc/sqitch.conf> can be used to
-store a system-wide default configuration.
+sqitch command's behavior. The F<./sqitch.conf> file local to each project is
+used to store the configuration for that project, and
+F<$HOME/.sqitch/sqitch.conf> is used to store a per-user configuration as
+fallback values for the F<./sqitch.conf> file. The file
+F<$(prefix>/etc/sqitch.conf> can be used to store a system-wide default
+configuration.
The variables are divided into sections, wherein the fully qualified variable
name of the variable itself is the last dot-separated segment and the section
View
76 t/config.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 300;
+use Test::More tests => 315;
#use Test::More 'no_plan';
use File::Spec;
use Test::MockModule;
@@ -29,6 +29,7 @@ can_ok $cmd, qw(file action context get get_all get_regex set add unset unset_al
is_deeply [$cmd->options], [qw(
file|config-file|f=s
+ local
user
system
int
@@ -63,6 +64,13 @@ is_deeply \@usage, ['Only one config file at a time.'],
'Should get error for multiple config files';
throws_ok { App::Sqitch::Command::config->configure( $sqitch->config, {
+ user => 1,
+ local => 1,
+}) } qr/USAGE/, 'Construct with user and local';
+is_deeply \@usage, ['Only one config file at a time.'],
+ 'Should get error for multiple config files';
+
+throws_ok { App::Sqitch::Command::config->configure( $sqitch->config, {
file => 't/sqitch.ini',
system => 1,
})} qr/USAGE/, 'Construct with file and system';
@@ -139,25 +147,32 @@ for my $spec (
}
##############################################################################
-# Test config file name.
+# Test context.
is $cmd->file, $sqitch->config->dir_file,
- 'Default config file should be local config file';
-is $cmd->action, undef, 'Default action should be undefined';
-is $cmd->context, 'project', 'Default context should be "project"';
+ 'Default context should be local context';
+is $cmd->action, undef, 'Default action should be undef';
+is $cmd->context, undef, 'Default context should be undef';
+
+# Test local file name.
+is_deeply App::Sqitch::Command::config->configure( $sqitch->config, {
+ local => 1,
+}), {
+ context => 'local',
+}, 'Local context should be local';
# Test user file name.
is_deeply App::Sqitch::Command::config->configure( $sqitch->config, {
user => 1,
}), {
context => 'user',
-}, 'User config file should be user';
+}, 'User context should be user';
# Test system file name.
is_deeply App::Sqitch::Command::config->configure( $sqitch->config, {
system => 1,
}), {
context => 'system',
-}, 'System config file should be system';
+}, 'System context should be system';
##############################################################################
# Test execute().
@@ -343,6 +358,23 @@ CONTEXT: {
is_deeply \@emit, [['/opt/local/pgsql/bin/psql']],
'Should have emitted the user core.pg.client';
@emit = ();
+
+ local $ENV{SQITCH_CONFIG} = file qw(t local.conf);
+ $sqitch->config->load;
+ ok $cmd = App::Sqitch::Command::config->new({
+ sqitch => $sqitch,
+ context => 'local',
+ action => 'get',
+ }), 'Create local config get command';
+ @emit = ();
+
+ ok $cmd->execute('core.pg.db_name'), 'Get local core.pg.db_name';
+ is_deeply \@emit, [['widgets']], 'Should have emitted the local core.pg.db_name';
+ @emit = ();
+
+ ok $cmd->execute('core.engine'), 'Get local core.engine';
+ is_deeply \@emit, [['pg']], 'Should have emitted the local core.engine';
+ @emit = ();
}
CONTEXT: {
@@ -369,12 +401,24 @@ CONTEXT: {
throws_ok { $cmd->execute('core.engine') } qr/UNFOUND/,
'Should fail when no user config file';
is_deeply \@unfound, [], 'Nothing should have been emitted';
+
+ local $ENV{SQITCH_CONFIG} = 'NONEXISTENT';
+ ok $cmd = App::Sqitch::Command::config->new({
+ sqitch => $sqitch,
+ context => 'local',
+ action => 'get',
+ }), 'Create another local config get command';
+ ok !-f $cmd->file, 'There should be no local config file';
+ throws_ok { $cmd->execute('core.engine') } qr/UNFOUND/,
+ 'Should fail when no local config file';
+ is_deeply \@unfound, [], 'Nothing should have been emitted';
}
##############################################################################
# Test list().
local $ENV{SQITCH_SYSTEM_CONFIG} = file qw(t sqitch.conf);
local $ENV{SQITCH_USER_CONFIG} = file qw(t user.conf);
+local $ENV{SQITCH_CONFIG} = file qw(t local.conf);
$sqitch->config->load;
ok $cmd = App::Sqitch::Command::config->new({
sqitch => $sqitch,
@@ -391,6 +435,7 @@ core.extension=ddl
core.mysql.client=/opt/local/mysql/bin/mysql
core.mysql.username=root
core.pg.client=/opt/local/pgsql/bin/psql
+core.pg.db_name=widgets
core.pg.host=localhost
core.pg.username=postgres
core.sql_dir=migrations
@@ -405,6 +450,7 @@ revert.to=gamma
CONTEXT: {
local $ENV{SQITCH_SYSTEM_CONFIG} = file qw(t sqitch.conf);
local $ENV{SQITCH_USER_CONFIG} = undef;
+ local $ENV{SQITCH_CONFIG} = undef;
$sqitch->config->load;
ok $cmd = App::Sqitch::Command::config->new({
sqitch => $sqitch,
@@ -447,6 +493,21 @@ core.sqlite.client=/opt/local/bin/sqlite3
"
]], 'Should only have emitted the user config list';
@emit = ();
+
+ $ENV{SQITCH_CONFIG} = file qw(t local.conf);
+ $sqitch->config->load;
+ ok $cmd = App::Sqitch::Command::config->new({
+ sqitch => $sqitch,
+ context => 'local',
+ action => 'list',
+ }), 'Create local config list command';
+ ok $cmd->execute, 'List the local config';
+ is_deeply \@emit, [[
+ "core.engine=pg
+core.pg.db_name=widgets
+"
+ ]], 'Should only have emitted the local config list';
+ @emit = ();
}
CONTEXT: {
@@ -538,6 +599,7 @@ is_deeply \@usage, ['Wrong number of arguments.'],
##############################################################################
# Test get with regex.
+delete $ENV{SQITCH_CONFIG};
$ENV{SQITCH_USER_CONFIG} = $file;
$sqitch->config->load;
ok $cmd = App::Sqitch::Command::config->new({
View
8 t/configuration.t
@@ -35,14 +35,14 @@ $ENV{SQITCH_USER_CONFIG} = 'FOO/BAR';
is $config->user_file, 'FOO/BAR',
'Should preferably get SQITCH_USER_CONFIG file from user_file';
-is $config->project_file, File::Spec->catfile(
+is $config->local_file, File::Spec->catfile(
File::Spec->curdir, 'sqitch.conf'
-), 'Project file should be correct';
-is $config->dir_file, $config->project_file, 'dir_file should alias project_file';
+), 'Local file should be correct';
+is $config->dir_file, $config->local_file, 'dir_file should alias local_file';
SQITCH_CONFIG: {
local $ENV{SQITCH_CONFIG} = 'sqitch.ini';
- is $config->project_file, 'sqitch.ini', 'project_file should prefer $SQITCH_CONFIG';
+ is $config->local_file, 'sqitch.ini', 'local_file should prefer $SQITCH_CONFIG';
is $config->dir_file, 'sqitch.ini', 'And so should dir_file';
}
View
2  t/init.t
@@ -87,7 +87,7 @@ make_path $test_dir;
END { remove_tree $test_dir }
chdir $test_dir;
END { chdir File::Spec->updir }
-my $conf_file = $sqitch->config->project_file;
+my $conf_file = $sqitch->config->local_file;
file_not_exists_ok $conf_file;
View
5 t/local.conf
@@ -0,0 +1,5 @@
+[core]
+ engine = pg
+
+[core.pg]
+ db_name = widgets
Please sign in to comment.
Something went wrong with that request. Please try again.