#!/usr/bin/env perl

use Object::Pad ':experimental(:all)';

package nosh;

class nosh;

use utf8;
use v5.40;

use lib 'lib';

use Getopt::Long
  qw(GetOptionsFromArray :config no_ignore_case auto_abbrev passthrough long_prefix_pattern=--?);

use List::Util 'all';
use IPC::Nosh;
use IPC::Nosh::Common;

field $argv  : param;
field $debug : mutator;

# field $stdin;
field $autoflush : mutator;
field $autochomp : mutator;
field $verbose   : mutator = 1;
field @barearg;
field $cmd : mutator = [];

ADJUST {    #{ # :params (:$autochomp, :$autoflush) {
    my %clidest = ( cmd => $cmd );

    GetOptionsFromArray(
        $argv, \%clidest, 'cmd=s{,}',
        'verbose+',
        'version',
        'help|?', 'debug+',    #'stdin'
        'autoflush!',
        'autochomp!',
        '<>' => sub ($barearg) {
            push @$cmd, map { split /\s+/, $_ } $barearg;
        }
    );

    foreach my ( $k, $v ) (%clidest) {
        $self->$k = $v if $v;
    }

}

method nosh ( $asdf = undef, %fdsa ) {

    my $run = run(
        $cmd,
        out => sub ($line) {
            say $line;
        },
        autoflush => $autoflush,
        autochomp => $autochomp,
    );
    dmsg $run;
}

method cli : common ($argv = \@ARGV) {
    my $self = $class->new( argv => $argv );
    $self->nosh;
}

package main;

use utf8;
use v5.40;

nosh->cli( \@ARGV );

use lib 'lib';
use IPC::Nosh::Mux;
use IPC::Nosh::Common;

# my @arr;

# tie @arr, 'IPC::Nosh::Mux',
#   autochomp => 1,
#   on        => {
#     line => sub ($line) {
#         warn $line;
#     }
#   };

# dmsg \@arr, tied @arr;
#  fn => './fsadfsdfsdf';
