App-OrgUtils

 view release on metacpan or  search on metacpan

script/list-org-priorities  view on Meta::CPAN

        },
        max => {
            summary => 'Only show priorities lower than or equal to this',
            schema => 'str*',
            tags => ['category:filtering'],
        },
        xmax => {
            summary => 'Only show priorities lower than this',
            schema => 'str*',
            tags => ['category:filtering'],
        },
    },
};
sub list_org_priorities {
    my %args = @_;

    my $tz = $args{time_zone} // $ENV{TZ} // "UTC";
    my %docs = App::OrgUtils::_load_org_files(
        $args{files}, {time_zone=>$tz});

    my @res;
    my %seen;
    for my $doc (values %docs) {
        my $i = 0;
        for (@{ $doc->priorities }) {
            $i++;

            if (defined $args{min}) {
                my $cmp = $doc->cmp_priorities($_, $args{min});
                next if !defined($cmp) || $cmp > 0;
            }
            if (defined $args{xmin}) {
                my $cmp = $doc->cmp_priorities($_, $args{xmin});
                next if !defined($cmp) || $cmp >= 0;
            }
            if (defined $args{max}) {
                my $cmp = $doc->cmp_priorities($_, $args{max});
                next if !defined($cmp) || $cmp < 0;
            }
            if (defined $args{xmax}) {
                my $cmp = $doc->cmp_priorities($_, $args{xmax});
                next if !defined($cmp) || $cmp <= 0;
            }

            if ($args{detail}) {
                push @res, {priority=>$_, order=>$i};
            } else {
                push @res, $_;
            }
        }
    }

    my $resmeta = {};
    if ($args{detail}) {
        $resmeta->{'table.fields'} = [qw/priority order/];
    }

    [200, "OK", \@res, $resmeta];
}

binmode STDOUT, ":encoding(utf8)";
Perinci::CmdLine::Any->new(url=>'/main/list_org_priorities')->run;

1;
# ABSTRACT: List all priorities defined in all Org files
# PODNAME: list-org-priorities

__END__

=pod

=encoding UTF-8

=head1 NAME

list-org-priorities - List all priorities defined in all Org files

=head1 VERSION

This document describes version 0.487 of list-org-priorities (from Perl distribution App-OrgUtils), released on 2024-01-09.

=head1 SYNOPSIS

=head1 OPTIONS

C<*> marks required options.

=head2 Main options

=over

=item B<--detail>, B<-l>

(No description)


=item B<--file>=I<s@>*

(No description)


Can also be specified as the 1st command-line argument and onwards.

Can be specified multiple times.

=item B<--files-json>=I<s>

See C<--file>.

Can also be specified as the 1st command-line argument and onwards.

=item B<--time-zone>=I<s>

Will be passed to parser's options.

If not set, TZ environment variable will be picked as default.


=back

=head2 Configuration options



( run in 1.233 second using v1.01-cache-2.11-cpan-39bf76dae61 )