<commit_before>namespace Microsoft.PowerShell.CoreConsoleHost
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Management.Automation;
    using System.Management.Automation.Host;
    using System.Management.Automation.Runspaces;
    using System.Text;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Linq;
    using PowerShell = System.Management.Automation.PowerShell;

    public static class Program
    {
        private enum Options {Help, File, Command, NoProfile, NonInteractive, EncodedCommand, Invalid};
        private class CommandOptions
        {
            public Options opt;
            public string optString;

            public CommandOptions(Options o, string s)
            {
                opt = o;
                optString = s;
            }
        }

        private static CommandOptions[] commandOptions = new CommandOptions[] 
            {
                new CommandOptions(Options.Help, "help"), 
                new CommandOptions(Options.Help, "?"), 
                new CommandOptions(Options.File, "file"),
                new CommandOptions(Options.Command, "command"), 
                new CommandOptions(Options.NoProfile, "noprofile"),
                new CommandOptions(Options.NonInteractive, "noninteractive"), 
                new CommandOptions(Options.EncodedCommand, "encodedcommand")
            };

        /// <summary>
        /// Creates and initiates the listener instance.
        /// </summary>
        public static void Main(string[] args)
        {
            // Setup the Assembly Load Context, which Core PowerShell uses to
            // analyze the libraries for types, functions, cmdlets, etc. and
            // provide the ability to load assemblies by file path. Doing this
            // here eliminates the need for a custom native host.
            PowerShellAssemblyLoadContextInitializer.SetPowerShellAssemblyLoadContext(string.Empty);


            // Argument parsing
            string initialScript = null;
            bool loadProfiles = true;
            bool interactive = true;

            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; ++i)
                {
                    string arg = args[i];
                    bool hasNext = (i+1) < args.Length;
                    string nextArg = hasNext ? args[i+1] : string.Empty;

                    // options start with "-" or "--"

                    string option;
                    if (arg.StartsWith("-"))
                    {
                        if (arg.StartsWith("--"))
                        {
                            option = arg.Remove(0, 2);
                        }
                        else
                        {
                            option = arg.Remove(0, 1);
                        }

                        Options bestOption = FindOption(option);

                        switch (bestOption)
                        {
                            case Options.Help:
                                Console.WriteLine(@"
usage: powershell[.exe] [ (--help | -h | -?) ]
                        [ (--file | -f) <filePath> ]
                        [ <script>.ps1 ]
                        [ (--command | -c) <string> ]
                        [ --noprofile | -nop ]
                        [ --noninteractive | -non ]
                        [ (--encodedcommand | -e) <base64Command> ]

SYNOPSIS

    Open PowerShell console can take none or one of several arguments.

OPTIONS

    No arguments
            Will launch PowerShell interactively.

    (--file | -f) <filePath>
            Given a file path, will execute as a PowerShell script.

    <script>.ps1
            Given a .ps1 script, will execute without needing --flag.

    (--command | -c) <string>
            Will execute given string as a PowerShell script.

    (--noprofile | -nop)
            Disables parsing of PowerShell profiles.

    (--help | -h | -?)
            Prints this text.

    (--noninteractive | -non)
            Does not present an interactive prompt to the user.

    (--encodedcommand | -e) <base64Command>
            Accepts a base-64-encoded string version of a command.
");
                                return;

                            case Options.NoProfile:
                                loadProfiles = false;
                                break;
                            case Options.File:
                                initialScript = Path.GetFullPath(nextArg);
                                ++i;
                                break;
                            case Options.Command:
                                if (nextArg == "-")
                                {
                                    initialScript = "\"TODO: read stdin using Console.OpenStandardInput\"";
                                }
                                else
                                {
                                    initialScript = nextArg;
                                }
                                ++i;
                                break;
                            case Options.NonInteractive:
                                interactive = false;
                                break;
                            case Options.EncodedCommand:
                                byte[] data = Convert.FromBase64String(nextArg);
                                initialScript = Encoding.UTF8.GetString(data);
                                ++i;
                                break;
                            default:
                                Console.WriteLine("Invalid command-line option: {0}. Use '-help' option to get a list of valid options.", arg);
                                return;
                        }
                    }
                    else  // not an option parameter
                    {
                        // lone argument is a script
                        if (!hasNext && arg.EndsWith(".ps1"))
                        {
                            initialScript = Path.GetFullPath(arg);<commit_msg>Fix -EncodedCommand implementation<commit_after>namespace Microsoft.PowerShell.CoreConsoleHost
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Management.Automation;
    using System.Management.Automation.Host;
    using System.Management.Automation.Runspaces;
    using System.Text;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Linq;
    using PowerShell = System.Management.Automation.PowerShell;

    public static class Program
    {
        private enum Options {Help, File, Command, NoProfile, NonInteractive, EncodedCommand, Invalid};
        private class CommandOptions
        {
            public Options opt;
            public string optString;

            public CommandOptions(Options o, string s)
            {
                opt = o;
                optString = s;
            }
        }

        private static CommandOptions[] commandOptions = new CommandOptions[] 
            {
                new CommandOptions(Options.Help, "help"), 
                new CommandOptions(Options.Help, "?"), 
                new CommandOptions(Options.File, "file"),
                new CommandOptions(Options.Command, "command"), 
                new CommandOptions(Options.NoProfile, "noprofile"),
                new CommandOptions(Options.NonInteractive, "noninteractive"), 
                new CommandOptions(Options.EncodedCommand, "encodedcommand")
            };

        /// <summary>
        /// Creates and initiates the listener instance.
        /// </summary>
        public static void Main(string[] args)
        {
            // Setup the Assembly Load Context, which Core PowerShell uses to
            // analyze the libraries for types, functions, cmdlets, etc. and
            // provide the ability to load assemblies by file path. Doing this
            // here eliminates the need for a custom native host.
            PowerShellAssemblyLoadContextInitializer.SetPowerShellAssemblyLoadContext(string.Empty);


            // Argument parsing
            string initialScript = null;
            bool loadProfiles = true;
            bool interactive = true;

            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; ++i)
                {
                    string arg = args[i];
                    bool hasNext = (i+1) < args.Length;
                    string nextArg = hasNext ? args[i+1] : string.Empty;

                    // options start with "-" or "--"

                    string option;
                    if (arg.StartsWith("-"))
                    {
                        if (arg.StartsWith("--"))
                        {
                            option = arg.Remove(0, 2);
                        }
                        else
                        {
                            option = arg.Remove(0, 1);
                        }

                        Options bestOption = FindOption(option);

                        switch (bestOption)
                        {
                            case Options.Help:
                                Console.WriteLine(@"
usage: powershell[.exe] [ (--help | -h | -?) ]
                        [ (--file | -f) <filePath> ]
                        [ <script>.ps1 ]
                        [ (--command | -c) <string> ]
                        [ --noprofile | -nop ]
                        [ --noninteractive | -non ]
                        [ (--encodedcommand | -e) <base64Command> ]

SYNOPSIS

    Open PowerShell console can take none or one of several arguments.

OPTIONS

    No arguments
            Will launch PowerShell interactively.

    (--file | -f) <filePath>
            Given a file path, will execute as a PowerShell script.

    <script>.ps1
            Given a .ps1 script, will execute without needing --flag.

    (--command | -c) <string>
            Will execute given string as a PowerShell script.

    (--noprofile | -nop)
            Disables parsing of PowerShell profiles.

    (--help | -h | -?)
            Prints this text.

    (--noninteractive | -non)
            Does not present an interactive prompt to the user.

    (--encodedcommand | -e) <base64Command>
            Accepts a base-64-encoded string version of a command.
");
                                return;

                            case Options.NoProfile:
                                loadProfiles = false;
                                break;
                            case Options.File:
                                initialScript = Path.GetFullPath(nextArg);
                                ++i;
                                break;
                            case Options.Command:
                                if (nextArg == "-")
                                {
                                    initialScript = "\"TODO: read stdin using Console.OpenStandardInput\"";
                                }
                                else
                                {
                                    initialScript = nextArg;
                                }
                                ++i;
                                break;
                            case Options.NonInteractive:
                                interactive = false;
                                break;
                            case Options.EncodedCommand:
                                byte[] data = Convert.FromBase64String(nextArg);
                                initialScript = Encoding.Unicode.GetString(data);
                                ++i;
                                break;
                            default:
                                Console.WriteLine("Invalid command-line option: {0}. Use '-help' option to get a list of valid options.", arg);
                                return;
                        }
                    }
                    else  // not an option parameter
                    {
                        // lone argument is a script
                        if (!hasNext && arg.EndsWith(".ps1"))
                        {
                            initialScript = Path.GetFullPath(arg);
{'fraction_non_alphanumeric': 0.08033843674456084, 'fraction_numerical': 0.00346494762288477, 'mean_word_length': 1.0312602291325697, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4901183', 'n_tokens_mistral': 2837, 'n_tokens_neox': 2623, 'n_words': 745}