<commit_before>﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text;

namespace AppHarbor.Commands
{
	[CommandHelp("Display help summary")]
	public class HelpCommand : Command
	{
		private readonly IEnumerable<Type> _commandTypes;
		private readonly TextWriter _writer;

		public HelpCommand(IEnumerable<Type> commandTypes, TextWriter writer)
		{
			_commandTypes = commandTypes;
			_writer = writer;
		}

		protected override void InnerExecute(string[] arguments)
		{
			_writer.WriteLine("Usage: appharbor COMMAND [command-options]");
			_writer.WriteLine("");

			_writer.WriteLine("Available commands:");
			_writer.WriteLine("");

			foreach (var commandType in _commandTypes.Where(x => x.IsClass)
				.OrderBy(x => GetScope(x))
				.ThenBy(x => x.Name))
			{
				var usageStringBuilder = new StringBuilder();

				var splitted = SplitUpperCase(commandType.Name).Where(x => x != "Command");
				usageStringBuilder.Append("  ");
				usageStringBuilder.Append(string.Join(" ", splitted.Reverse()));
				var helpAttribute = commandType.GetCustomAttributes(true).OfType<CommandHelpAttribute>().Single();
					usageStringBuilder.Append(string.Format(" {0}", helpAttribute.Options));

				while (usageStringBuilder.Length < 30)
				{
					usageStringBuilder.Append(" ");
				}

				_writer.Write(usageStringBuilder.ToString().ToLower());
				_writer.Write(string.Concat("#  ", helpAttribute.Description));

				if (!string.IsNullOrEmpty(helpAttribute.Alias))
				{
					_writer.Write(" (\"{0}\")", helpAttribute.Alias);
				}
				_writer.WriteLine();
			}
		}

		private static string GetScope(Type x)
		{
			return SplitUpperCase(x.Name).Where(y => y != "Command").Last();
		}

		private static string Reverse(string sz)
		{
			if (string.IsNullOrEmpty(sz) || sz.Length == 1)
			{
				return sz;
			}

			var chars = sz.ToCharArray();
			Array.Reverse(chars);

			return new string(chars);
		}

		private static string[] SplitUpperCase(string source)
		{
			if (source == null)
				return new string[] { }; //Return empty array.

			if (source.Length == 0)
				return new string[] { "" };
<commit_msg>Write common options in HelpCommand<commit_after>﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text;

namespace AppHarbor.Commands
{
	[CommandHelp("Display help summary")]
	public class HelpCommand : Command
	{
		private readonly IEnumerable<Type> _commandTypes;
		private readonly TextWriter _writer;

		public HelpCommand(IEnumerable<Type> commandTypes, TextWriter writer)
		{
			_commandTypes = commandTypes;
			_writer = writer;
		}

		protected override void InnerExecute(string[] arguments)
		{
			_writer.WriteLine("Usage: appharbor COMMAND [command-options]");
			_writer.WriteLine("");

			_writer.WriteLine("Available commands:");
			_writer.WriteLine("");

			foreach (var commandType in _commandTypes.Where(x => x.IsClass)
				.OrderBy(x => GetScope(x))
				.ThenBy(x => x.Name))
			{
				var usageStringBuilder = new StringBuilder();

				var splitted = SplitUpperCase(commandType.Name).Where(x => x != "Command");
				usageStringBuilder.Append("  ");
				usageStringBuilder.Append(string.Join(" ", splitted.Reverse()));
				var helpAttribute = commandType.GetCustomAttributes(true).OfType<CommandHelpAttribute>().Single();
					usageStringBuilder.Append(string.Format(" {0}", helpAttribute.Options));

				while (usageStringBuilder.Length < 30)
				{
					usageStringBuilder.Append(" ");
				}

				_writer.Write(usageStringBuilder.ToString().ToLower());
				_writer.Write(string.Concat("#  ", helpAttribute.Description));

				if (!string.IsNullOrEmpty(helpAttribute.Alias))
				{
					_writer.Write(" (\"{0}\")", helpAttribute.Alias);
				}
				_writer.WriteLine();
			}

			_writer.WriteLine();
			_writer.WriteLine("Common options:");
			OptionSet.WriteOptionDescriptions(_writer);
		}

		private static string GetScope(Type x)
		{
			return SplitUpperCase(x.Name).Where(y => y != "Command").Last();
		}

		private static string Reverse(string sz)
		{
			if (string.IsNullOrEmpty(sz) || sz.Length == 1)
			{
				return sz;
			}

			var chars = sz.ToCharArray();
			Array.Reverse(chars);

			return new string(chars);
		}

		private static string[] SplitUpperCase(string source)
		{
			if (source == null)
				return new string[] { }; //Return empty array.

			if (source.Length == 0)
				return new string[] { "" };

{'fraction_non_alphanumeric': 0.13804564591181032, 'fraction_numerical': 0.002658985153999557, 'mean_word_length': 4.015555555555555, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6329067', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1329, 'n_words': 286}