<commit_before># sketchify command for converting CFEngine policy bundles into sketches
# <NAME>, July 1st, 2013
# <EMAIL>

use Data::Dumper;
use File::Copy;

######################################################################

%COMMANDS =
  (
   'sketchify' =>
   [[
     'sketchify FILE.cf',
     'Interactively generate a sketch from FILE.cf. You will be prompted for all the necessary information.',
     '(\S+)(?:\s+(\S+)(?:\s+(\S+)(?:\s+(\S+))?)?)?'
    ]]
  );

######################################################################

sub prompt_sketch_datum
{
    my $prompt = shift;
    my $default = shift;
    my $validate = shift;
    my $errmsg = shift;

    my $value;
    my $valid;
    do
    {
        $value = Util::single_prompt($prompt, $default);
        if (!defined($value) || $value eq 'STOP')
        {
            Util::warning("Stopping at your request.\n");
            return (undef, 1);
        }
        if ($validate)
        {
            $valid = $validate->($value);
            if (!$valid)
            {
                Util::error("Error: $errmsg\n");
            }
        }
        else
        {
            $valid = 1;
        }
    } while (!$valid);
    return ($value, undef);
}

sub command_sketchify
{
    my $file = shift;
    my $sketchname = shift;
    my $bundle = shift;
    my $outputdir = shift;

    # Some general parameters
    my $sketchname_regex = qr(^(\w+)(::\w+)*$);
    my @valid_types = qw(string boolean list array);

    # Basic checks
    unless (-f $file)<commit_msg>Skeleton for new `sketchify` command<commit_after># sketchify command for converting CFEngine policy bundles into sketches
# <NAME>, July 1st, 2013
# <EMAIL>

use Data::Dumper;
use File::Copy;

######################################################################

%COMMANDS =
  (
   'sketchify_old' =>
   [[
     '-sketchify_old FILE.cf',
     'Interactively generate a sketch from FILE.cf. You will be prompted for all the necessary information.',
     '(\S+)(?:\s+(\S+)(?:\s+(\S+)(?:\s+(\S+))?)?)?'
    ]],
   'sketchify' =>
   [[
     'sketchify SKETCH | FILE.cf',
     'Interactively generate a sketch from FILE.cf, or review and update an existing SKETCH. You will be prompted for all the necessary information.',
     '(\S+)'
    ]]
  );

######################################################################

sub prompt_sketch_datum
{
    my $prompt = shift;
    my $default = shift;
    my $validate = shift;
    my $errmsg = shift;

    my $value;
    my $valid;
    do
    {
        $value = Util::single_prompt($prompt, $default);
        if (!defined($value) || $value eq 'STOP')
        {
            Util::warning("Stopping at your request.\n");
            return (undef, 1);
        }
        if ($validate)
        {
            $valid = $validate->($value);
            if (!$valid)
            {
                Util::error("Error: $errmsg\n");
            }
        }
        else
        {
            $valid = 1;
        }
    } while (!$valid);
    return ($value, undef);
}

sub command_sketchify
{
    my $thing = shift;

    my $file;
    my $sketchname;
    my $bundle;
    my $outputdir;
    my $file_base;

    # Some general parameters
    my $sketchname_regex = qr(^(\w+)(::\w+)*$);
    my @valid_types = qw(string boolean list array);

    # Verify if $thing is a sketch or a file
    if ($thing =~ /\.cf$/)
    {
        $file = $thing;
        unless (-f $file)
        {
            Util::error("Error: I cannot find file $file.\n");
            return;
        }
        $file_base = basename($file);
    }
    else
    {
        my $sk=main::get_sketch($thing);
        if (exists($sk->{$thing}))
        {
            $sketchname = $thing;
        }
        else
        {
            Util::error("Error: I cannot find sketch $thing.\n");
            return;
        }
    }

    Util::message("Processing ".($sketchname ? "sketch $sketchname" : "file $file")."\n");
}

sub command_sketchify_old
{
    my $file = shift;
    my $sketchname = shift;
    my $bundle = shift;
    my $outputdir = shift;

    # Some general parameters
    my $sketchname_regex = qr(^(\w+)(::\w+)*$);
    my @valid_types = qw(string boolean list array);

    # Basic checks
    unless (-f $file)
{'fraction_non_alphanumeric': 0.21176470588235294, 'fraction_numerical': 0.0032941176470588237, 'mean_word_length': 2.1535608308605343, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3746412', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1314, 'n_words': 346}