Example #1
0
        /// <summary>
        /// setup properties of clp and shell env from the settings object and envrionment variables
        /// </summary>
        /// <param name="clp">clp</param>
        /// <param name="settings">clp settings</param>
        void ShellInitFromSettings(
            ICommandLineProcessor clp,
            ICommandLineProcessorSettings settings
            )
        {
            var ctx = clp.CommandEvaluationContext;

            _console.Out.EnableAvoidEndOfLineFilledWithBackgroundColor = ctx.ShellEnv.GetValue <bool>(ShellEnvironmentVar.settings_console_enableAvoidEndOfLineFilledWithBackgroundColor);
            var prompt = ctx.ShellEnv.GetValue <string>(ShellEnvironmentVar.settings_console_prompt);

            clp.CommandLineReader.SetDefaultPrompt(prompt);

            var pathexts        = ctx.ShellEnv.GetValue <List <string> >(ShellEnvironmentVar.pathExt);
            var pathextinit     = ctx.ShellEnv.GetDataValue(ShellEnvironmentVar.pathExtInit);
            var pathextinittext = (string)pathextinit.Value;

            if (!string.IsNullOrWhiteSpace(pathextinittext))
            {
                pathextinittext += ShellEnvironment.SystemPathSeparator;
            }
            pathextinittext += settings.PathExtInit.Replace(";", ShellEnvironment.SystemPathSeparator);
            pathextinit.SetValue(pathextinittext);
            var exts = pathextinittext.Split(ShellEnvironment.SystemPathSeparator);

            foreach (var ext in exts)
            {
                pathexts.AddUnique(ext);
            }

            ctx.ShellEnv.SetValue(ShellEnvironmentVar.settings_clp_shellExecBatchExt, settings.ShellExecBatchExt);
        }
Example #2
0
        public CommandLineProcessor(
            IConsole console,
            ICommandBatchProcessor cbp,
            ICommandsAlias cal,
            ISyntaxAnalyser sa,
            IModuleManager modManager,
            IHookManager hookManager,
            IExternalParserExtension parserExt,
            ICommandLineProcessorSettings settings = null
            )
        {
            _instanceId++;
#if DBG_DI_INSTANCE
            System.Console.Out.WriteLine($"new CLP #{_InstanceId}");
#endif
            Console = console;
            ExternalParserExtension        = parserExt;
            parserExt.CommandLineProcessor = this;
            SyntaxAnalyzer        = sa;
            ModuleManager         = modManager;
            HookManager           = hookManager;
            _settings             = settings;
            CommandBatchProcessor = cbp;
            CommandsAlias         = cal;
        }
Example #3
0
        /// <summary>
        /// clp init (defaults streams are console streams)
        /// </summary>
        public void Init(
            string[] args,
            ICommandLineProcessorSettings settings,
            CommandEvaluationContext context = null
            )
        {
            _args = args;

            context ??= new CommandEvaluationContext(
                this,
                Console.Out,
                Console.In,
                Console.Err,
                null
                );
            CommandEvaluationContext = context;
        }
Example #4
0
        /// <summary>
        /// shell init actions sequence<br/>
        /// use system in,out,err TODO: plugable to any stream - just add parameters
        /// </summary>
        /// <param name="args">orbsh args</param>
        /// <param name="settings">(launch) settings object</param>
        /// <param name="context">shell default command evaluation context.Provides null to build a new one</param>
        public void ShellInit(
            string[] args,
            IConsole console,
            ICommandLineProcessorSettings settings,
            CommandEvaluationContext context = null
            )
        {
            _clp.Init(args, settings, context);

            context = _clp.CommandEvaluationContext;    // get final clp command evaluation context

            context.Logger.MuteLogErrors = true;

            _clp.Settings.Initialize(context);

            _shellArgsOptionBuilder.SetArgs(args);

            var appliedSettings = new List <ShellArgValue>();

            _shellArgsOptionBuilder
            .SetCommandOperationContextOptions(context, ref appliedSettings)
            .SetCommandLineProcessorOptions(context, ref appliedSettings)
            .ImportSettingsFromJSon(context, ref appliedSettings);

            // init from settings

            context.Logger.IsEchoEnabled = !context.Settings.IsQuiet;
            context.Out.IsMute           = context.Settings.IsQuiet;

            ShellInitFromSettings(_clp, settings);

            // pre console init
            if (!context.Settings.IsMute && console.DefaultForeground != null)
            {
                cons.ForegroundColor = console.DefaultForeground.Value;
            }

            ConsoleInit(_clp.CommandEvaluationContext);

            InitShellInitFolder();

            // clp info output
            if (settings.PrintInfo)
            {
                _clp.PrintInfo(_clp.CommandEvaluationContext);
            }

            #region -- load kernel modules --

            var a = Assembly.GetExecutingAssembly();
            context.Logger.Info(_clp.CommandEvaluationContext.ShellEnv.Colors.Log + $"loading kernel module: '{a}' ... ", true, false);
            var moduleSpecification = _clp.ModuleManager.RegisterModule(_clp.CommandEvaluationContext, a);
            context.Logger.Done(moduleSpecification.Info.GetDescriptor(context));

            a = Assembly.Load(settings.KernelCommandsModuleAssemblyName);
            context.Logger.Info(_clp.CommandEvaluationContext.ShellEnv.Colors.Log + $"loading kernel commands module: '{a}' ... ", true, false);
            moduleSpecification = _clp.ModuleManager.RegisterModule(_clp.CommandEvaluationContext, a);
            context.Logger.Done(moduleSpecification.Info.GetDescriptor(context));

            #endregion

            _clp.CommandEvaluationContext.Logger.MuteLogErrors = false;

            #region -- load modules ---

            var mpath = _clp.Settings.ModulesInitFilePath;
            context.Logger.Info(_clp.CommandEvaluationContext.ShellEnv.Colors.Log + $"loading modules: '{FileSystemPath.UnescapePathSeparators(mpath)}' ... ", true, false);

            ModulesInit(context, mpath);
            context.Logger.Done("modules loaded");

            #endregion

            #region init from user profile

            context.Logger.Info(_clp.CommandEvaluationContext.ShellEnv.Colors.Log + $"init user profile from: '{FileSystemPath.UnescapePathSeparators(_clp.Settings.AppDataRoamingUserFolderPath)}' ... ", true, false);

            InitUserProfileFolder();

            _clp.PostInit();

            context.Logger.Done();

            CreateUserSettingsFile();

            context.Logger.Info(_clp.CommandEvaluationContext.ShellEnv.Colors.Log + $"restoring user history file: '{FileSystemPath.UnescapePathSeparators(_clp.Settings.HistoryFilePath)}' ... ", true, false);

            CreateRestoreUserHistoryFile();

            context.Logger.Done();
            context.Logger.Info(_clp.CommandEvaluationContext.ShellEnv.Colors.Log + $"loading user aliases: '{FileSystemPath.UnescapePathSeparators(_clp.Settings.CommandsAliasFilePath)}' ... ", true, false);

            CreateRestoreUserAliasesFile();

            context.Logger.Done();

            #endregion

            if (appliedSettings.Count > 0)
            {
                context.Logger.Info(_clp.CommandEvaluationContext.ShellEnv.Colors.Log + $"shell args: {string.Join(" ", appliedSettings)}");
            }

            // end inits
            console.Out.Echoln();

            _clp.PostInit();
        }