コード例 #1
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();
        }