コード例 #1
0
        /// <summary>
        /// Echo method
        /// </summary>
        /// <param name="context">echo context</param>
        public void Echo(EchoEvaluationContext context)
        {
            var options = new TableFormattingOptions(context.CommandEvaluationContext.ShellEnv.TableFormattingOptions)
            {
                UnfoldCategories = false,
                UnfoldItems      = false,
                IsRawModeEnabled = true
            };

            var cols = context.CommandEvaluationContext.ShellEnv.Colors;
            var tb   = new Table(
                ("property", typeof(string), $"{cols.Label}{{0}}{cols.Default}")
                );

            tb.AddColumns(("value", typeof(object)));

            tb.AddRow("id", Id);
            tb.AddRow("registration", Registration);
            tb.AddRow("version", Version);
            tb.AddRow("description", Description);
            tb.AddRow("summary", Summary);
            tb.AddRow("title", Title);
            tb.AddRow("icon url", IconUrl);
            tb.AddRow("license url", LicenseUrl);
            tb.AddRow("project url", ProjectUrl);
            tb.AddRow("tags", Tags);
            tb.AddRow("authors", Authors);
            tb.AddRow("total downloads", TotalDownloads);
            tb.AddRow("verified", Verified);
            tb.AddRow("packages types", PackageTypes);
            tb.AddRow("versions", Versions);
            tb.Echo(new EchoEvaluationContext(context, options));
        }
コード例 #2
0
        public CommandResult <IDataObject> Inf(
            CommandEvaluationContext context,
            [Parameter(0, "variable namespace of a value")] string varPath
            )
        {
            context.Variables.GetObject(varPath, out var obj);

            var options = new TableFormattingOptions(context.ShellEnv.TableFormattingOptions)
            {
                UnfoldCategories = false,
                UnfoldItems      = false,
                IsRawModeEnabled = true
            };
            var props = new Dictionary <string, object>();

            if (obj is DataObject o)
            {
                props.Add("name", o.Name);
                props.Add("is read only", o.IsReadOnly);
                props.Add("namespace", o.ObjectPath);
                props.Add("has attributes", o.HasAttributes);
            }
            else
            if (obj is DataValue v)
            {
                props.Add("name", v.Name);
                props.Add("type", v.ValueType?.UnmangledName(false));
                props.Add("is read only", v.IsReadOnly);
                props.Add("has attributes", v.HasAttributes);
                props.Add("has value", v.HasValue);
                props.Add("namespace", v.ObjectPath);
                props.Add("value", v.Value);
            }
            else
            {
                throw new Exception($"can't get information for a variable member");
            }

            Table dt = new Table();

            dt.AddColumns("property", "value")
            .SetFormat("property", $"{context.ShellEnv.Colors.Label}{{0}}{Rdc}");
            dt.Columns[0].DataType = typeof(string);
            dt.Columns[1].DataType = typeof(object);

            foreach (var kv in props)
            {
                var row = dt.NewRow();
                row["property"] = kv.Key;
                row["value"]    = kv.Value;
                dt.Rows.Add(row);
            }

            dt.Echo(new EchoEvaluationContext(context.Out, context, options));

            return(new CommandResult <IDataObject>(obj as IDataObject));
        }
コード例 #3
0
        public CommandResult <List <IDataObject> > Vars(
            CommandEvaluationContext context,
            [Parameter(0, "variable namespace or value path below the root namespace. if specified and exists, output is built from this point, otherwise outputs all variables from env root", true)] string varPath,
            [Option("u", "unfold-namespace", "unfold namespaces")] bool unfoldNamespaces     = false,
            [Option("o", "unfold-value", "unfold values of type object")] bool unfoldObjects = false,
            [Option("p", "parse", "echo string values in parsed mode (ansi and directives). By default strings objects are represented by raw text")] bool parsed = false
            )
        {
            object obj;

            if (varPath == null)
            {
                obj = context.Variables.RootObject;
            }
            else
            {
                context.Variables.GetObject(varPath, out obj);
            }

            var options = new TableFormattingOptions(context.ShellEnv.TableFormattingOptions)
            {
                UnfoldCategories = unfoldNamespaces,
                UnfoldItems      = unfoldObjects,
                IsRawModeEnabled = !parsed
            };

            if (obj is DataValue value)
            {
                var lst = new List <IDataObject>()
                {
                    value
                };
                var resultValue = new CommandResult <List <IDataObject> >(lst);
                var wrapper     = new DataObject("");
                wrapper.Set(new string[] { "x" }, value);
                wrapper.Echo(new EchoEvaluationContext(context.Out, context, options));
                return(resultValue);
            }
            else
            {
                if (obj is IDataObject envVars)
                {
                    var values = envVars.GetAttributes();
                    envVars.Echo(new EchoEvaluationContext(context.Out, context, options));
                    return(new CommandResult <List <IDataObject> >(values));
                }
                else
                {
                    // directly dump object members
                    EchoPrimitives.DumpObject(obj, new EchoEvaluationContext(context.Out, context, options));
                    return(new CommandResult <List <IDataObject> >(null));
                }
            }
        }
コード例 #4
0
 public TableFormattingOptions(TableFormattingOptions o)
 {
     base.InitFrom(o);
     NoBorders         = o.NoBorders;
     PadLastColumn     = o.PadLastColumn;
     Layout            = o.Layout;
     UnfoldCategories  = o.UnfoldCategories;
     UnfoldItems       = o.UnfoldItems;
     ColumnLeftMargin  = o.ColumnLeftMargin;
     ColumnRightMargin = o.ColumnRightMargin;
 }