blib/lib/App/karr/Cmd/Materialize.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 55 CC 6 SCAR 30.9
CC
6
Cov
0%
execute
42.0
BEGIN
2.0
BEGIN
2.0
CRAP 22.0
1 # ABSTRACT: Write the ref-backed board out as a tasks/ file view
2  
3 package App::karr::Cmd::Materialize;
4 our $VERSION = '0.602';
5 use Moo;
6 use MooX::Cmd;
7 use MooX::Options (
8 usage_string => 'USAGE: karr materialize [--dir PATH] [--force] [--json]',
9 );
10 use App::karr::Role::BoardAccess;
11 use App::karr::Role::Output;
12 use App::karr::Error qw( command_hint );
13  
14 with 'App::karr::Role::BoardAccess', 'App::karr::Role::Output';
15  
16  
17 option force => (
18 is => 'ro',
19 doc => 'Replace git-tracked config.yml / tasks cards at the destination',
20 );
21  
22 sub execute {
23 my ($self, $args_ref, $chain_ref) = @_;
24  
25 $self->check_positional_args($args_ref, 0);
26  
27 # Read-only: materialize reflects the current local refs into files, so it
28 # syncs nothing (matching the reading commands list/show/board).
29 my $store = $self->store;
30 # Same sentence as everywhere else, with the way out spelled as the command
31 # instead of quoted inside the prose, and last (ticket k263).
32 die "No karr board found:\n" . command_hint('init') . "\n"
33 unless $store->has_board_refs;
34  
35 # Asked before materialize_to runs, so the answer is about the working tree
36 # as the project left it: with --force a tracked card the sweep is about to
37 # delete is still on disk to be found, and none of the cards we are about to
38 # write (all untracked) can be mistaken for the project's.
39 my @owned = $store->project_owned_view_paths( $self->git_root->stringify );
40  
41 my $board_dir = $store->materialize_to(
42 $self->git_root->stringify,
43 force => $self->force,
44 );
45  
46 # The file view we just wrote must never be committed; ensure the board-root
47 # .gitignore covers it (idempotent -- a no-op once init or a prior run added
48 # the entries). Done regardless of --json so the guard never depends on the
49 # output format.
50 #
51 # Unless the project got there first, which is the one thing that stops it:
52 # init already declines to claim paths the project tracks, and materialize
53 # appending them anyway put back the exact untrue claim init had just refused
54 # to make (tickets #89, #100). The entry would be inert -- git applies no
55 # ignore rule to a tracked file -- so all it can do is mislead.
56 my @ignored = @owned ? () : $store->ensure_gitignore( $self->git_root->stringify );
57  
58 my @tasks = $store->load_tasks;
59  
60 # The view is a task collection (like `list`), so --json always emits an
61 # array -- never a bare object for a one-task board.
62 return $self->print_json([ map { $_->to_json_hash } @tasks ]) if $self->json;
63  
64 printf STDERR "Materialized %d task(s) to %s\n", scalar @tasks, $board_dir;
65 printf STDERR "Added .gitignore entries for the file view: %s\n", join( ', ', @ignored )
66 if @ignored;
67 printf STDERR "Left .gitignore alone: git already tracks content at %s.\n"
68 . "Those paths belong to the project, not to karr's file view, so karr is not\n"
69 . "claiming them here.\n", join( ', ', @owned )
70 if @owned;
71 }
72  
73 1;
74  
75 __END__