App-CSVUtils-csv_mix_formulas
view release on metacpan or search on metacpan
script/csv-mix-formulas view on Meta::CPAN
#!perl
# Note: This script is a CLI for Riap function /App/CSVUtils/csv_mix_formulas/csv_mix_formulas
# and generated automatically using Perinci::CmdLine::Gen version 0.502
use 5.010001;
use strict;
use warnings;
use Log::ger;
use Perinci::CmdLine::Any;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2024-02-24'; # DATE
our $DIST = 'App-CSVUtils-csv_mix_formulas'; # DIST
our $VERSION = '0.002'; # VERSION
my $cmdline = Perinci::CmdLine::Any->new(
url => "/App/CSVUtils/csv_mix_formulas/csv_mix_formulas",
program_name => "csv-mix-formulas",
log => 1,
read_config => 0,
read_env => 0,
use_utf8 => 1,
);
$cmdline->run;
# ABSTRACT: Mix several formulas/recipes (lists of ingredients and their weights/volumes) into one, and output the combined formula
# PODNAME: csv-mix-formulas
__END__
=pod
=encoding UTF-8
=head1 NAME
csv-mix-formulas - Mix several formulas/recipes (lists of ingredients and their weights/volumes) into one, and output the combined formula
=head1 VERSION
This document describes version 0.002 of csv-mix-formulas (from Perl distribution App-CSVUtils-csv_mix_formulas), released on 2024-02-24.
=head1 SYNOPSIS
B<csv-mix-formulas> B<L<--help|/"--help, -h, -?">> (or B<L<-h|/"--help, -h, -?">>, B<L<-?|/"--help, -h, -?">>)
B<csv-mix-formulas> B<L<--version|/"--version, -v">> (or B<L<-v|/"--version, -v">>)
B<csv-mix-formulas> [B<L<--debug|/"--debug">>|B<L<--log-level|/"--log-level=s">>=I<level>|B<L<--quiet|/"--quiet">>|B<L<--trace|/"--trace">>|B<L<--verbose|/"--verbose">>] [B<L<--format|/"--format=s">>=I<name>|B<L<--json|/"--json">>] [B<L<--ingredient-...
=head1 DESCRIPTION
Each formula is a CSV comprised of at least two fields. The first field (by
default literally the first field, but can also be specified using
C<--ingredient-field>) is assumed to contain the name of ingredients. The second
field (by default literally the second field, but can also be specified using
C<--weight-field>) is assumed to contain the weight of ingredients. A percent
form is recognized and will be converted to its decimal form (e.g. "60%" or
"60.0 %" will become 0.6).
Example, mixing this CSV:
ingredient,%weight,extra-field1,extra-field2
water,80,foo,bar
sugar,15,foo,bar
citric acid,0.3,foo,bar
strawberry syrup,4.7,foo,bar
and this:
ingredient,%weight,extra-field1,extra-field2,extra-field3
lemon syrup,5.75,bar,baz,qux
citric acid,0.25,bar,baz,qux
sugar,14,bar,baz,qux
water,80,bar,baz,qux
will result in the following CSV. Note: 1) for the header, except for the first
two fields which are the ingredient name and weight which will contain the mixed
formula, the other fields will simply collect values from all the CSV files. 2)
for sorting order: decreasing weight then by name.
ingredient,%weight,extra-field1,extra-field2,extra-field3
water,80,foo,bar,qux
sugar,14.5,foor,bar,qux
lemon syrup,2.875,bar,baz,qux
strawberry syrup,2.35,foo,bar,
citric acid,0.275,foo,bar,qux
Keywords: compositions, mixture, combine
=head1 OPTIONS
C<*> marks required options.
=head2 Main options
=over
=item B<--ingredient-field>=I<s>
Specify field which contain the ingredient names.
=item B<--weight-field>=I<s>
Specify field which contain the weights.
=back
=head2 Formatting options
script/csv-mix-formulas view on Meta::CPAN
Shortcut for --log-level=debug.
=item B<--log-level>=I<s>
Set log level.
By default, these log levels are available (in order of increasing level of
importance, from least important to most): C<trace>, C<debug>, C<info>,
C<warn>/C<warning>, C<error>, C<fatal>. By default, the level is usually set to
C<warn>, which means that log statements with level C<info> and less important
levels will not be shown. To increase verbosity, choose C<info>, C<debug>, or
C<trace>.
For more details on log level and logging, as well as how new logging levels can
be defined or existing ones modified, see L<Log::ger>.
=item B<--quiet>
Shortcut for --log-level=error.
=item B<--trace>
Shortcut for --log-level=trace.
=item B<--verbose>
Shortcut for --log-level=info.
=back
=head2 Output options
=over
=item B<--format>=I<s>
Choose output format, e.g. json, text.
Default value:
undef
Output can be displayed in multiple formats, and a suitable default format is
chosen depending on the application and/or whether output destination is
interactive terminal (i.e. whether output is piped). This option specifically
chooses an output format.
=item B<--inplace>
Output to the same file as input.
Normally, you output to a different file than input. If you try to output to the
same file (C<-o INPUT.csv -O>) you will clobber the input file; thus the utility
prevents you from doing it. However, with this C<--inplace> option, you can
output to the same file. Like perl's C<-i> option, this will first output to a
temporary file in the same directory as the input file then rename to the final
file at the end. You cannot specify output file (C<-o>) when using this option,
but you can specify backup extension with C<-b> option.
Some caveats:
=over
=item * if input file is a symbolic link, it will be replaced with a regular file;
=item * renaming (implemented using C<rename()>) can fail if input filename is too long;
=item * value specified in C<-b> is currently not checked for acceptable characters;
=item * things can also fail if permissions are restrictive;
=back
=item B<--inplace-backup-ext>=I<s>, B<-b>
Extension to add for backup of input file.
Default value:
""
In inplace mode (C<--inplace>), if this option is set to a non-empty string, will
rename the input file using this extension as a backup. The old existing backup
will be overwritten, if any.
=item B<--json>
Set output format to json.
=item B<--naked-res>
When outputing as JSON, strip result envelope.
Default value:
0
By default, when outputing as JSON, the full enveloped result is returned, e.g.:
[200,"OK",[1,2,3],{"func.extra"=>4}]
The reason is so you can get the status (1st element), status message (2nd
element) as well as result metadata/extra result (4th element) instead of just
the result (3rd element). However, sometimes you want just the result, e.g. when
you want to pipe the result for more post-processing. In this case you can use
C<--naked-res> so you just get:
[1,2,3]
=item B<--output-always-quote>
Whether to always quote values.
When set to false (the default), values are quoted only when necessary:
field1,field2,"field three contains comma (,)",field4
When set to true, then all values will be quoted:
"field1","field2","field three contains comma (,)","field4"
=item B<--output-escape-char>=I<s>
Specify character to escape value in field in output CSV, will be passed to Text::CSV_XS.
This is like C<--input-escape-char> option but for output instead of input.
Defaults to C<\\> (backslash). Overrides C<--output-tsv> option.
=item B<--output-filename>=I<s>, B<-o>
Output filename.
Use C<-> to output to stdout (the default if you don't specify this option).
Encoding of output file is assumed to be UTF-8.
=item B<--output-header>
( run in 0.746 second using v1.01-cache-2.11-cpan-39bf76dae61 )