Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="definition"></param>
        /// <returns></returns>
        public ModelHelp GenerateModelHelp <TModel>(IModelBindingDefinition <TModel> definition)
        {
            var modelHelp = new ModelHelp
            {
                SwitchDelimiter = definition.SwitchDelimiter,
                Members         = definition.Members.Select(GenerateMemberHelp).ToArray(),
                HelpText        = definition.CommandModelDescription,
            };

            if (string.IsNullOrEmpty(modelHelp.HelpText))
            {
                var helpAttribute = typeof(TModel)
#if NETSTANDARD_1_3
                                    .GetTypeInfo()
#endif
                                    .GetCustomAttributes(true).OfType <ResourceMemberHelpAttributeBase>().SingleOrDefault();

                if (helpAttribute != null)
                {
                    modelHelp.HelpText = helpAttribute.GetHelpText();
                }
            }

            return(modelHelp);
        }
Exemplo n.º 2
0
        public void WriteHelp(ModelHelp modelHelp, TextWriter textWriter)
        {
            if (!string.IsNullOrWhiteSpace(modelHelp.HelpText))
            {
                WriteDescription(modelHelp.HelpText, textWriter);
            }

            WriteUsage(modelHelp, textWriter);
            WriteSwitches(modelHelp, textWriter);
        }
        protected override void WriteUsage(ModelHelp modelHelp, TextWriter writer)
        {
            var values = modelHelp.Members.Where(m => m.OrdinalIndex.HasValue && m.OrdinalIndex != 0)
                .OrderBy(m => m.OrdinalIndex.Value)
                .Select(m => m.Name)
                .Concat(modelHelp.Members
                    .Where(m => m.OrdinalIndex.HasValue == false)
                    .Select(m => String.Format("[{0}]", String.Join("|", m.Switches.Select(s => modelHelp.SwitchDelimiter + s).ToArray()))));

            var dictionary = new Dictionary<string, string>
            {
                {this._cmdName, String.Join(" ", values.ToArray())}
            };

            WriteJustifiedOutput(dictionary, CommandSamplePadding);
        }
Exemplo n.º 4
0
        private void WriteUsage(ModelHelp modelHelp, TextWriter textWriter)
        {
            if (modelHelp == null) throw new ArgumentNullException("modelHelp");
            if (textWriter == null) throw new ArgumentNullException("textWriter");

            var location = Assembly.GetEntryAssembly().Location;
            textWriter.Write(Path.GetFileNameWithoutExtension(location));

            foreach (var member in modelHelp.Members)
            {
                textWriter.Write(" [{0}]", modelHelp.SwitchDelimiter + member.Switches.Single());
            }

            textWriter.WriteLine(" URL");
            textWriter.WriteLine();
        }
Exemplo n.º 5
0
        private void WriteSwitches(ModelHelp modelHelp, TextWriter textWriter)
        {
            if (modelHelp == null) throw new ArgumentNullException("modelHelp");
            if (textWriter == null) throw new ArgumentNullException("textWriter");

            foreach (var member in modelHelp.Members)
            {
                var memberSwitch = member.Switches.Single();
                textWriter.Write("  {0}{1}", modelHelp.SwitchDelimiter, memberSwitch);

                var spaces = new string(' ', 3 - memberSwitch.Length);
                textWriter.Write(spaces);

                textWriter.WriteLine("{0}", member.HelpText);
            }
        }