Esempio n. 1
0
        private static string NormalizeScope(string scope, string @default)
        {
            switch (scope)
            {
            case "cfg":
            case "conf":
            case "config":
                return(Scopes.Configuration);

            case "sys":
            case "system":
                return(Scopes.System);

            case "usr":
            case "user":
                return(Scopes.User);

            case "pers":
            case "persist":
            case "persistent":
                return(Scopes.Persistent);

            case "tmp":
            case "temp":
            case "temporary":
                return(Scopes.Temporary);

            case "proc":
            case "process":
            case "env":
            case "environment":
                return(Scopes.Process);

            case null when @default != null:

                // ReSharper disable once TailRecursiveCall
                return(VariableSegment.NormalizeScope(@default, null));

            default:
                return(Scopes.Invalid);
            }
        }
Esempio n. 2
0
        public ShellResult Execute(AppConfig config, object input = null, bool captureOutput = false)
        {
            var normalizedScope = VariableSegment.NormalizeScope(
                this.Scope ?? config.DefaultVariableScope,
                config.DefaultVariableScope
                );

            if (normalizedScope == Scopes.Invalid)
            {
                throw new InvalidOperationException($"Invalid variable scope '{this.Scope}'");
            }

            if (input is null)
            {
                return(ShellResult.Ok(this.GetValue(config, normalizedScope)));
            }

            this.SetValue(config, normalizedScope, input);
            return(ShellResult.Ok(captureOutput ? input : null));
        }