コード例 #1
0
ファイル: Init.cs プロジェクト: olivierh59500/inVtero.net
        private static void InitImpl()
        {
            ArgPipelineObjectMapper.CurrentMapper = new JObjectArgPipelineMapper();

            PipelineOutputFormatter.RegisterFormatter(typeof(JObject), FuncPipelineOutputFormatter.Create((obj) =>
            {
                JObject jObj = (JObject)obj;
                ConsoleTableBuilder builder  = new ConsoleTableBuilder();
                List <ConsoleString> headers = new List <ConsoleString>()
                {
                    new ConsoleString("PROPERTY", ConsoleColor.Yellow), new ConsoleString("VALUE", ConsoleColor.Yellow)
                };
                List <List <ConsoleString> > rows = new List <List <ConsoleString> >();
                foreach (var prop in jObj.Properties())
                {
                    rows.Add(new List <ConsoleString>()
                    {
                        new ConsoleString(prop.Name, ConsoleColor.Gray), new ConsoleString("" + prop.Value, ConsoleColor.Green)
                    });
                }

                var jObjRet = builder.FormatAsTable(headers, rows);
                jObjRet     = new ConsoleString("Pipeline output of type JObject: \n") + jObjRet;
                return(jObjRet);
            }));
        }
コード例 #2
0
        public void ConsoleTableTestLongWord()
        {
            ConsoleProvider.Current.BufferWidth = 160;
            ConsoleTableBuilder builder = new ConsoleTableBuilder();

            var columns = new List <ConsoleString>()
            {
                new ConsoleString("Word 1"), new ConsoleString("Word 2")
            };
            var rows = new List <List <ConsoleString> >()
            {
                new List <ConsoleString>()
                {
                    new ConsoleString(" ThisIsAVeryLongWord"), new ConsoleString("Hello. ThisIsAVeryLongWord ThisIsAnother AnotherVeryLongWord")
                }
            };

            var columnOverflowBehaviors = new List <ColumnOverflowBehavior>()
            {
                new SmartWrapOverflowBehavior()
                {
                    DefineMaxWidthBasedOnConsoleWidth = false, MaxWidthBeforeWrapping = 10
                },
                new SmartWrapOverflowBehavior()
                {
                    DefineMaxWidthBasedOnConsoleWidth = false, MaxWidthBeforeWrapping = 10
                }
            };

            builder.FormatAsTable(columns, rows, rowPrefix: "", columnOverflowBehaviors: columnOverflowBehaviors);
        }
コード例 #3
0
        public void ConsoleTableBasic()
        {
            ConsoleTableBuilder builder = new ConsoleTableBuilder();

            var columns = new List <ConsoleString>()
            {
                new ConsoleString("NAME"), new ConsoleString("ADDRESS"), new ConsoleString("DESCRIPTION")
            };
            var rows = new List <List <ConsoleString> >()
            {
                new List <ConsoleString>()
                {
                    new ConsoleString("Adam Abdelhamed"), new ConsoleString("One Microsoft Way, Redmond WA 98052"), new ConsoleString("The author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!  We love PowerArgs so much cuz it is awesome and great.  Yay!!!!  In fact, PowerArgs is so fun that nothing in the entire universe is more fun.  ")
                },
                new List <ConsoleString>()
                {
                    new ConsoleString("Alicia Abdelhamed"), new ConsoleString("Two Microsoft Way, Redmond WA 98052"), new ConsoleString("The wife of the author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!")
                },
            };


            var output = builder.FormatAsTable(columns, rows);
            var outstr = output.ToString();

            var expected =
                @"
NAME                ADDRESS                               DESCRIPTION                                                                                                                                                                                                                                               
Adam Abdelhamed     One Microsoft Way, Redmond WA 98052   The author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!  We love PowerArgs so much cuz it is awesome and great.  Yay!!!!  In fact, PowerArgs is so fun that nothing in the entire universe is more fun.     
Alicia Abdelhamed   Two Microsoft Way, Redmond WA 98052   The wife of the author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!                                                                                                                                         
".TrimStart();

            Helpers.AssertAreEqualWithDiffInfo(expected.Replace("\r\n", "\n"), outstr.Replace("\r\n", "\n"));
        }
コード例 #4
0
        public void ConsoleTableTestMultiOptions()
        {
            ConsoleProvider.Current.BufferWidth = 160;
            ConsoleTableBuilder builder = new ConsoleTableBuilder();

            var columns = new List <ConsoleString>()
            {
                new ConsoleString("NAME"), new ConsoleString("ADDRESS"), new ConsoleString("DESCRIPTION")
            };
            var rows = new List <List <ConsoleString> >()
            {
                new List <ConsoleString>()
                {
                    new ConsoleString("Adam Abdelhamed"), new ConsoleString("One Microsoft Way, Redmond WA 98052"), new ConsoleString("The author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!  We love PowerArgs so much cuz it is awesome and great.  Yay!!!!  In fact, PowerArgs is so fun that nothing in the entire universe is more fun.  ")
                },
                new List <ConsoleString>()
                {
                    new ConsoleString("Alicia Abdelhamed"), new ConsoleString("Two Microsoft Way, Redmond WA 98052"), new ConsoleString("The wife of the author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!")
                },
            };

            var columnOverflowBehaviors = new List <ColumnOverflowBehavior>()
            {
                new TruncateOverflowBehavior()
                {
                    ColumnWidth = 7
                },
                new SmartWrapOverflowBehavior()
                {
                    DefineMaxWidthBasedOnConsoleWidth = false, MaxWidthBeforeWrapping = 15
                },
                new SmartWrapOverflowBehavior(),
            };


            var output = builder.FormatAsTable(columns, rows, rowPrefix: "", columnOverflowBehaviors: columnOverflowBehaviors);
            var outstr = output.ToString();

            var expected =
                @"
NAME         ADDRESS           DESCRIPTION
Adam...      One Microsoft     The author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!  We love PowerArgs so
             Way, Redmond      much cuz it is awesome and great.  Yay!!!!  In fact, PowerArgs is so fun that nothing in the entire universe is more fun.  
             WA 98052          
Alic...      Two Microsoft     The wife of the author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!
             Way, Redmond      
             WA 98052".TrimStart();


            Helpers.AssertAreEqualWithDiffInfo(expected.Replace("\r\n", "\n"), outstr.Replace("\r\n", "\n"));
        }
コード例 #5
0
        public void ConsoleTableBasic()
        {
            ConsoleTableBuilder builder = new ConsoleTableBuilder();

            var columns = new List<ConsoleString>() { new ConsoleString("NAME"), new ConsoleString("ADDRESS"), new ConsoleString("DESCRIPTION") };
            var rows = new List<List<ConsoleString>>()
            {
                new List<ConsoleString>(){ new ConsoleString("Adam Abdelhamed"), new ConsoleString("One Microsoft Way, Redmond WA 98052"), new ConsoleString("The author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!  We love PowerArgs so much cuz it is awesome and great.  Yay!!!!  In fact, PowerArgs is so fun that nothing in the entire universe is more fun.  ") },
                new List<ConsoleString>(){ new ConsoleString("Alicia Abdelhamed"), new ConsoleString("Two Microsoft Way, Redmond WA 98052"), new ConsoleString("The wife of the author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!") },
            };

            var output = builder.FormatAsTable(columns, rows);
            var outstr = output.ToString();

            var expected =
            @"
            NAME                ADDRESS                               DESCRIPTION
            Adam Abdelhamed     One Microsoft Way, Redmond WA 98052   The author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!  We love PowerArgs so much cuz it is awesome and great.  Yay!!!!  In fact, PowerArgs is so fun that nothing in the entire universe is more fun.
            Alicia Abdelhamed   Two Microsoft Way, Redmond WA 98052   The wife of the author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!
            ".TrimStart();

            Helpers.AssertAreEqualWithDiffInfo(expected.Replace("\r\n", "\n"), outstr.Replace("\r\n", "\n"));
        }
コード例 #6
0
        private void PaintInternal(ConsoleBitmap context)
        {
            if (this.Height < 5)
            {
                context.DrawString("Grid can't render in a space this small", 0, 0);
                return;
            }

            if (VisibleColumns.Count == 0)
            {
                context.DrawString(NoVisibleColumnsMessage.ToConsoleString(DefaultColors.H1Color), 0, 0);
                return;
            }

            List <ConsoleString>          headers           = new List <ConsoleString>();
            List <List <ConsoleString> >  rows              = new List <List <ConsoleString> >();
            List <ColumnOverflowBehavior> overflowBehaviors = new List <ColumnOverflowBehavior>();


            if (VisibleColumns.Where(c => c.WidthPercentage != 0).Count() == 0)
            {
                foreach (var col in VisibleColumns)
                {
                    col.WidthPercentage = 1.0 / VisibleColumns.Count;
                }
            }

            foreach (var header in VisibleColumns)
            {
                headers.Add(header.ColumnDisplayName);
                var colWidth = (int)(header.WidthPercentage * this.Width);

                if (header.OverflowBehavior is SmartWrapOverflowBehavior)
                {
                    (header.OverflowBehavior as SmartWrapOverflowBehavior).MaxWidthBeforeWrapping = colWidth;
                }
                else if (header.OverflowBehavior is TruncateOverflowBehavior)
                {
                    (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth = (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth == 0 ? colWidth : (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth;
                }

                overflowBehaviors.Add(header.OverflowBehavior);
            }

            int viewIndex = visibleRowOffset;

            foreach (var item in DataView.Items)
            {
                List <ConsoleString> row = new List <ConsoleString>();
                int columnIndex          = 0;
                foreach (var col in VisibleColumns)
                {
                    var value        = PropertyResolver(item, col.ColumnName.ToString());
                    var displayValue = value == null ? "<null>".ToConsoleString() : (value is ConsoleString ? (ConsoleString)value : value.ToString().ToConsoleString());

                    if (viewIndex == SelectedIndex && this.CanFocus)
                    {
                        if (this.SelectionMode == GridSelectionMode.Row || (this.SelectionMode == GridSelectionMode.Cell && columnIndex == selectedColumnIndex))
                        {
                            displayValue = new ConsoleString(displayValue.ToString(), this.Background, HasFocus ? DefaultColors.FocusColor : DefaultColors.SelectedUnfocusedColor);
                        }
                    }

                    row.Add(displayValue);
                    columnIndex++;
                }
                viewIndex++;
                rows.Add(row);
            }

            ConsoleTableBuilder builder = new ConsoleTableBuilder();
            ConsoleString       table;

            table = builder.FormatAsTable(headers, rows, RowPrefix.ToString(), overflowBehaviors, Gutter);


            if (FilterText != null)
            {
                table = table.Highlight(FilterText, DefaultColors.HighlightContrastColor, DefaultColors.HighlightColor, StringComparison.InvariantCultureIgnoreCase);
            }

            if (DataView.IsViewComplete == false)
            {
                table += "Loading more rows...".ToConsoleString(DefaultColors.H1Color);
            }
            else if (DataView.IsViewEndOfData && DataView.Items.Count == 0)
            {
                table += NoDataMessage.ToConsoleString(DefaultColors.H1Color);
            }
            else if (DataView.IsViewEndOfData)
            {
                if (ShowEndIfComplete)
                {
                    table += EndOfDataMessage.ToConsoleString(DefaultColors.H1Color);
                }
            }
            else
            {
                table += MoreDataMessage;
            }
            context.DrawString(table, 0, 0);


            if (FilteringEnabled)
            {
            }
        }
コード例 #7
0
        public void ConsoleTableTestMultiOptions()
        {
            ConsoleProvider.Current.BufferWidth = 160;
            ConsoleTableBuilder builder = new ConsoleTableBuilder();

            var columns = new List<ConsoleString>() { new ConsoleString("NAME"), new ConsoleString("ADDRESS"), new ConsoleString("DESCRIPTION") };
            var rows = new List<List<ConsoleString>>()
            {
                new List<ConsoleString>(){ new ConsoleString("Adam Abdelhamed"), new ConsoleString("One Microsoft Way, Redmond WA 98052"), new ConsoleString("The author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!  We love PowerArgs so much cuz it is awesome and great.  Yay!!!!  In fact, PowerArgs is so fun that nothing in the entire universe is more fun.  ") },
                new List<ConsoleString>(){ new ConsoleString("Alicia Abdelhamed"), new ConsoleString("Two Microsoft Way, Redmond WA 98052"), new ConsoleString("The wife of the author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!") },
            };

            var columnOverflowBehaviors = new List<ColumnOverflowBehavior>()
            {
                new TruncateOverflowBehavior(){ColumnWidth = 7},
                new SmartWrapOverflowBehavior(){DefineMaxWidthBasedOnConsoleWidth = false, MaxWidthBeforeWrapping = 15},
                new SmartWrapOverflowBehavior(),
            };

            var output = builder.FormatAsTable(columns, rows, rowPrefix: "", columnOverflowBehaviors: columnOverflowBehaviors);
            var outstr = output.ToString();

            var expected =
            @"
            NAME         ADDRESS           DESCRIPTION
            Adam...      One Microsoft     The author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!  We love PowerArgs so
             Way, Redmond      much cuz it is awesome and great.  Yay!!!!  In fact, PowerArgs is so fun that nothing in the entire universe is more fun.
             WA 98052
            Alic...      Two Microsoft     The wife of the author of PowerArgs, the world's greatest command line parser and invoker.  Hooray for PowerArgs!
             Way, Redmond
             WA 98052".TrimStart();

            Helpers.AssertAreEqualWithDiffInfo(expected.Replace("\r\n", "\n"), outstr.Replace("\r\n", "\n"));
        }
コード例 #8
0
        /// <summary>
        /// Renders the table given a data context
        /// </summary>
        /// <param name="context">the data context</param>
        /// <returns>the console friendly table, as a ConsoleString</returns>
        public ConsoleString Evaluate(DocumentRendererContext context)
        {
            var eval = context.EvaluateExpression(this.EvalToken.Value);

            if(eval == null)
            {
                throw new DocumentRenderException("NullReference for '" + this.EvalToken.Value + "'", this.EvalToken);
            }
            else if(eval is IEnumerable == false)
            {
                throw new DocumentRenderException("'" + this.EvalToken.Value + "' is not enumerable", this.EvalToken);
            }

            IEnumerable collection = (IEnumerable)eval;

            List<ConsoleString> headers = new List<ConsoleString>();
            List<List<ConsoleString>> rows = new List<List<ConsoleString>>();
            List<ColumnOverflowBehavior> overflows = new List<ColumnOverflowBehavior>();

            for (int colIndex = 0; colIndex < Columns.Count; colIndex++ )
            {
                var col = Columns[colIndex];
                var colValue = col.Value;

                if (colValue.EndsWith("+"))
                {
                    colValue = colValue.Substring(0, colValue.Length - 1);
                    overflows.Add(new SmartWrapOverflowBehavior());
                    if(colIndex != Columns.Count-1)
                    {
                        throw new DocumentRenderException("The auto expand indicator '+' can only be used on the last column", col);
                    }
                }
                else
                {
                    overflows.Add(new GrowUnboundedOverflowBehavior());
                }

                if (colValue.Contains(">"))
                {
                    var newColName = colValue.Split('>')[1];
                    headers.Add(new ConsoleString(newColName, ConsoleColor.Yellow));
                }
                else
                {
                    headers.Add(new ConsoleString(colValue, ConsoleColor.Yellow));
                }
            }

            foreach(var element in collection)
            {
                if(element is CommandLineArgument && ((CommandLineArgument)element).OmitFromUsage)
                {
                    continue;
                }

                var row = new List<ConsoleString>();
                foreach (var col in Columns)
                {
                    string propName;
                    if (col.Value.Contains(">"))
                    {
                        propName = col.Value.Split('>')[0];
                    }
                    else
                    {
                        propName = col.Value;
                    }

                    if(propName.EndsWith("+"))
                    {
                        propName = propName.Substring(0, propName.Length - 1);
                    }

                    var propToGet = element.GetType().GetProperty(propName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
                    if (propToGet == null) throw new DocumentRenderException("'" + propName + "' is not a valid property for type '" + element.GetType().FullName + "'", col);
                    var value = propToGet.GetValue(element, null);

                    ConsoleString valueString;

                    if(value != null)
                    {
                        valueString = new ConsoleString(value.ToString());
                        if (ShowDefaultValuesForArguments && element is CommandLineArgument && propToGet.Name == "Description" && ((CommandLineArgument)element).DefaultValue != null)
                        {
                            valueString+= new ConsoleString(" [Default='" + ((CommandLineArgument)element).DefaultValue.ToString() + "'] ", ConsoleColor.DarkGreen);
                        }
                    }
                    else
                    {
                        valueString = ConsoleString.Empty;
                    }
                    row.Add(valueString);
                }
                rows.Add(row);

                if(ShowPossibleValuesForArguments && element is CommandLineArgument && ((CommandLineArgument)element).IsEnum)
                {
                    foreach (var val in ((CommandLineArgument)element).EnumValuesAndDescriptions)
                    {
                        List<ConsoleString> possibilitiesRow = new List<ConsoleString>();
                        for (int i = 0; i < Columns.Count - 1; i++)
                        {
                            possibilitiesRow.Add(ConsoleString.Empty);
                        }
                        possibilitiesRow.Add(new ConsoleString(val, ConsoleColor.DarkGreen));
                        rows.Add(possibilitiesRow);
                    }
                }
            }

            string rowPrefix = "";
            for(int i = 0; i < indent; i++)
            {
                rowPrefix += " ";
            }

            ConsoleTableBuilder builder = new ConsoleTableBuilder();
            var tableText = builder.FormatAsTable(headers, rows, rowPrefix: rowPrefix, columnOverflowBehaviors: overflows);

            // remove the prefix from the first row
            tableText = tableText.Substring(indent);
            var tableTextStr = tableText.ToString();
            return tableText;
        }
コード例 #9
0
ファイル: Grid-View.cs プロジェクト: adamabdelhamed/PowerArgs
        private void PaintInternal(ConsoleBitmap context)
        {
            if (this.Height < 5)
            {
                context.DrawString("Grid can't render in a space this small", 0, 0);
                return;
            }

            if (VisibleColumns.Count == 0)
            {
                context.DrawString(NoVisibleColumnsMessage.ToConsoleString(Application.Theme.H1Color), 0, 0);
                return;
            }

            List<ConsoleString> headers = new List<ConsoleString>();
            List<List<ConsoleString>> rows = new List<List<ConsoleString>>();
            List<ColumnOverflowBehavior> overflowBehaviors = new List<ColumnOverflowBehavior>();

            if (VisibleColumns.Where(c => c.WidthPercentage != 0).Count() == 0)
            {
                foreach (var col in VisibleColumns)
                {
                    col.WidthPercentage = 1.0 / VisibleColumns.Count;
                }
            }

            foreach (var header in VisibleColumns)
            {
                headers.Add(header.ColumnDisplayName);
                var colWidth = (int)(header.WidthPercentage * this.Width);

                if (header.OverflowBehavior is SmartWrapOverflowBehavior)
                {
                    (header.OverflowBehavior as SmartWrapOverflowBehavior).MaxWidthBeforeWrapping = colWidth;
                }
                else if (header.OverflowBehavior is TruncateOverflowBehavior)
                {
                    (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth = colWidth;
                }

                overflowBehaviors.Add(header.OverflowBehavior);
            }

            int viewIndex = visibleRowOffset;
            foreach (var item in DataView.Items)
            {
                List<ConsoleString> row = new List<ConsoleString>();
                int columnIndex = 0;
                foreach (var col in VisibleColumns)
                {
                    var value = PropertyResolver(item, col.ColumnName.ToString());
                    var displayValue = value == null ? "<null>".ToConsoleString() : (value is ConsoleString ? (ConsoleString)value : value.ToString().ToConsoleString());

                    if (viewIndex == SelectedIndex)
                    {
                        if (this.SelectionMode == GridSelectionMode.Row || (this.SelectionMode == GridSelectionMode.Cell && columnIndex == selectedColumnIndex))
                        {
                            displayValue = new ConsoleString(displayValue.ToString(), this.Background, HasFocus ? Application.Theme.FocusColor : Application.Theme.SelectedUnfocusedColor);
                        }
                    }

                    row.Add(displayValue);
                    columnIndex++;
                }
                viewIndex++;
                rows.Add(row);
            }

            ConsoleTableBuilder builder = new ConsoleTableBuilder();
            ConsoleString table;
            #if PROFILING
            using (new TimeProfiler("Grid.FormatAsTable"))
            {
            #endif
                table = builder.FormatAsTable(headers, rows, RowPrefix.ToString(), overflowBehaviors, Gutter);
            #if PROFILING
            }
            #endif

            if (FilterText != null)
            {
                table = table.Highlight(FilterText, Application.Theme.HighlightContrastColor, Application.Theme.HighlightColor, StringComparison.InvariantCultureIgnoreCase);
            }

            if (DataView.IsViewComplete == false)
            {
                table += "Loading more rows...".ToConsoleString(Application.Theme.H1Color);
            }
            else if (DataView.IsViewEndOfData && DataView.Items.Count == 0)
            {
                table += NoDataMessage.ToConsoleString(Application.Theme.H1Color);
            }
            else if (DataView.IsViewEndOfData)
            {
                table += EndOfDataMessage.ToConsoleString(Application.Theme.H1Color);
            }
            else
            {
                table += "more data below".ToConsoleString(Application.Theme.H1Color);
            }
            context.DrawString(table, 0, 0);

            if (FilteringEnabled)
            {

            }
        }
コード例 #10
0
ファイル: CompactConsole.cs プロジェクト: jiaw37/PowerArgs
        public ConsoleString CreateAssistiveText()
        {
            if (IsAssistanceEnabled == false)
            {
                return(ConsoleString.Empty);
            }

            List <CommandLineAction> candidates = def.Actions.Where(a => a.Metadata.WhereAs <OmitFromUsageDocs>().None()).ToList();

            if (InputBox.Value.Length > 0)
            {
                var command = InputBox.Value.Split(" ".ToConsoleString()).FirstOrDefault();
                command    = command ?? ConsoleString.Empty;
                candidates = candidates.Where(a => a.DefaultAlias.StartsWith(command.StringValue, StringComparison.OrdinalIgnoreCase)).ToList();

                if (candidates.Count == 0)
                {
                    return($"\nNo actions start with {InputBox.Value.ToString()}".ToRed());
                }
            }

            var builder = new ConsoleTableBuilder();


            var headers = new List <ConsoleString>()
            {
                "command".ToYellow(),
                "description".ToYellow(),
                "example".ToYellow(),
            };

            var rows = new List <List <ConsoleString> >();

            foreach (var candidate in candidates)
            {
                var row = new List <ConsoleString>();
                rows.Add(row);
                row.Add(candidate.DefaultAlias.ToLower().ToCyan());
                row.Add(Parse(candidate.Description));
                row.Add(candidate.HasExamples == false ? ConsoleString.Empty : candidate.Examples.First().Example.ToGreen());



                if (candidates.Count == 1)
                {
                    foreach (var arg in candidate.Arguments.Where(a => a.Metadata.Where(m => m is OmitFromUsageDocs).None()))
                    {
                        var argDescription = !arg.HasDefaultValue ? ConsoleString.Empty : Parse($"[DarkYellow]\\[Default: [Yellow]{arg.DefaultValue}[DarkYellow]] ");
                        argDescription += string.IsNullOrEmpty(arg.Description) ? ConsoleString.Empty : Parse(arg.Description);
                        argDescription += !arg.IsEnum ? ConsoleString.Empty : "values: ".ToYellow() + string.Join(", ", arg.EnumValuesAndDescriptions).ToYellow();

                        row = new List <ConsoleString>();
                        rows.Add(row);
                        row.Add(" -".ToWhite() + arg.DefaultAlias.ToLower().ToWhite() + (arg.IsRequired ? "*".ToRed() : ConsoleString.Empty));
                        row.Add(argDescription);
                        row.Add(ConsoleString.Empty);
                    }
                }
            }
            return(builder.FormatAsTable(headers, rows));
        }
コード例 #11
-1
ファイル: Init.cs プロジェクト: abbottdev/PowerArgs
        private static void InitImpl()
        {
            ArgPipelineObjectMapper.CurrentMapper = new JObjectArgPipelineMapper();

            PipelineOutputFormatter.RegisterFormatter(typeof(JObject), FuncPipelineOutputFormatter.Create((obj) =>
            {
                JObject jObj = (JObject)obj;
                ConsoleTableBuilder builder = new ConsoleTableBuilder();
                List<ConsoleString> headers = new List<ConsoleString>() { new ConsoleString("PROPERTY", ConsoleColor.Yellow), new ConsoleString("VALUE", ConsoleColor.Yellow) };
                List<List<ConsoleString>> rows = new List<List<ConsoleString>>();
                foreach (var prop in jObj.Properties())
                {
                    rows.Add(new List<ConsoleString>() { new ConsoleString(prop.Name, ConsoleColor.Gray), new ConsoleString("" + prop.Value, ConsoleColor.Green) });
                }

                var jObjRet = builder.FormatAsTable(headers, rows);
                jObjRet = new ConsoleString("Pipeline output of type JObject: \n") + jObjRet;
                return jObjRet;
            }));
        }