Пример #1
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            foreach (var file in _file.GetDuplicates())
            {
                _consoleWriter.WriteLine("--- Duplicate ---");
                _consoleWriter.WriteLine($"CreatedAt (oldest): {file.CreatedAt}");
                _consoleWriter.WriteLine($"File Size: {file.Size}");
                _consoleWriter.WriteLine($"File Tags: {string.Join(", ", file.GetTags().Result.Select(t => t.FullName))}");

                var table = new ConsoleTable(5);
                foreach (var path in file.GetPaths().Result)
                {
                    var fileInfo = new FileInfo(path);

                    if (fileInfo.Exists)
                    {
                        table.Append(fileInfo.CreationTimeUtc, fileInfo.Length.HumanSize(), fileInfo.Name, string.Empty, fileInfo.Directory.FullName);
                    }
                    else
                    {
                        table.Append(string.Empty, string.Empty, fileInfo.Name, "*", fileInfo.Directory.FullName);
                    }
                }

                table.WriteTo(_consoleWriter);
                _consoleWriter.WriteLine();
            }

            _consoleWriter.WriteLine("Files with an asterisk (*) are in the database, but at the given path they seem to be deleted.");

            return(true);
        }
Пример #2
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            var search = string.Join(" ", arguments);

            _consoleWriter.WriteLine($"Find Files: {search}");

            var files = _file.Search(search).ToList();

            if (files.Any())
            {
                var table = FileTable();
                foreach (var file in files)
                {
                    if (options.HasOption <OpenOption>())
                    {
                        FileHelper.OpenWithAssociatedProgram(file.Path);
                    }

                    table.Append(file.Hash.Result.ShortHash(), file.CreatedAt, file.Size.HumanSize(), file.Path);
                }
                table.WriteTo(_consoleWriter);
            }
            else
            {
                _consoleWriter.WriteLine("No files found for your search query...");
            }

            return(true);
        }
Пример #3
0
 public ClientHost(IOptionParser optionParser, IRestClientProtocol clientProtocol, IRestDataTransferProtocol dataTransferProtocol, ICommandDispatcher commandDispatcher, ICommandFactory commandFactory)
 {
     _optionParser         = optionParser;
     _clientProtocol       = clientProtocol;
     _dataTransferProtocol = dataTransferProtocol;
     _commandDispatcher    = commandDispatcher;
     _commandFactory       = commandFactory;
 }
Пример #4
0
 private bool PrintOverview(IOptionParser options)
 {
     PrintHelpHeader();
     PrintHelpCommands(_container.Resolve <IEnumerable <ICommand> >());
     PrintHelpOptions(_container.Resolve <IEnumerable <IOption> >());
     PrintTagVariables(options);
     PrintHelpExamples();
     return(true);
 }
Пример #5
0
        private void ParseShortOption(IOptionParser parser, OptionToken token)
        {
            if (!m_ShortOptionList.TryGetValue(token.Value[0], out OptionData optionData))
            {
                throw new OptionUnknownException(token.ToString(parser));
            }

            ParseOptionParameter(parser, optionData, token);
        }
Пример #6
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            foreach (var project in _projects.GetProjects())
            {
                FormatProject(project);
            }

            return(true);
        }
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            var projects = arguments.ToList();

            return(projects.Count switch
            {
                0 => NotEnoughArguments(),
                _ => DestroyProjects(projects)
            });
Пример #8
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            _logger.LogTrace("Help Command executed");

            var firstArgument = arguments.FirstOrNone();

            return(firstArgument.Match(
                       none: PrintOverview(options),
                       some: argument => PrintSpecificHelp(argument, _container.Resolve <IEnumerable <ICommand> >())));
        }
Пример #9
0
        public bool Execute(IEnumerable <string> lazyArguments, IOptionParser options)
        {
            var arguments = lazyArguments.ToList();

            return(arguments.Count switch
            {
                0 => NotEnoughArguments(),
                1 => CreateProject(arguments.First()),
                _ => TooManyArguments()
            });
Пример #10
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            if (arguments.Any())
            {
                _consoleWriter.WriteLine("Too many arguments given, the plugin command does not take any arguments.");
                return(false);
            }

            return(ListPlugins());
        }
Пример #11
0
        public bool Execute(IEnumerable <string> lazyArguments, IOptionParser options)
        {
            var arguments = lazyArguments.ToList();

            return(arguments.Count switch
            {
                0 => NotEnoughArguments(),
                1 => ExportProject(arguments.First(), CurrentDirectory),
                2 => ExportProject(arguments.First(), arguments.Last()),
                _ => TooManyArguments()
            });
Пример #12
0
        private void ParseLongOption(IOptionParser parser, OptionToken token)
        {
            string option = parser.LongOptionCaseInsensitive ? token.Value.ToLowerInvariant() : token.Value;

            if (!m_LongOptionList.TryGetValue(option, out OptionData optionData))
            {
                throw new OptionUnknownException(token.ToString(parser));
            }

            ParseOptionParameter(parser, optionData, token);
        }
Пример #13
0
        public bool ExportFiles(IEnumerable <string> lazyArguments, IOptionParser options, string longCommand)
        {
            var arguments = lazyArguments.ToList();

            return(arguments.Count switch
            {
                0 => NotEnoughArguments(longCommand),
                1 => NotEnoughArguments(longCommand),
                2 => ExportFiles(GetSearchArgument(arguments), GetDestinationPath(arguments)),
                _ => TooManyArguments(longCommand)
            });
Пример #14
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            foreach (var path in _file.GetPaths())
            {
                if (File.Exists(path) == false)
                {
                    _consoleWriter.WriteLine($"File '{path}' does not exist, removed from index");
                }
            }

            return(true);
        }
Пример #15
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            foreach (var argument in _filePathExtractor.FromFilePatterns(arguments, false))
            {
                _consoleWriter.WriteLine($"File: {argument}");

                if (FileType(argument) is { } fileType)
                {
                    _consoleWriter.WriteLine($"Category : {fileType.Category}");
                    _consoleWriter.WriteLine($"Name     : {fileType.Name}");
                    _consoleWriter.WriteLine($"Extension: {string.Join(",", fileType.Extensions)}");
                }
Пример #16
0
        private void ParseOption(IOptionParser parser, OptionToken token)
        {
            switch (token.Token)
            {
            case OptionTokenKind.ShortOption:
                ParseShortOption(parser, token);
                break;

            case OptionTokenKind.LongOption:
                ParseLongOption(parser, token);
                break;
            }
        }
Пример #17
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            var project = arguments.First();

            if (_projects.GetProjects().Contains(project))
            {
                _settings[DB.Constants.ProjectDatabaseKey] = project;
                _consoleWriter.WriteLine($"You switched to project '{project}'");
                return(true);
            }

            _consoleWriter.WriteLine($"There is no project with the name '{project}' please create it first.");
            return(false);
        }
Пример #18
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            var table = StatisticsTable();

            foreach (var(key, value) in _db.GetStatistics())
            {
                table.Append(key, "=", value);
            }

            _consoleWriter.WriteLine("Statistics:");
            _consoleWriter.WriteLine();
            table.WriteTo(_consoleWriter);

            return(true);
        }
Пример #19
0
 public bool Execute(IEnumerable <string> arguments, IOptionParser options)
 {
     foreach (var filePath in _filePathExtractor.FromFilePatterns(arguments, false))
     {
         IEnumerable <Directory> directories = ReadMetadata(filePath);
         foreach (var directory in directories)
         {
             foreach (var tag in directory.Tags)
             {
                 _consoleWriter.WriteLine($"{directory.Name} - {tag.Name} ({tag.Type}) = {tag.Description}");
             }
         }
     }
     return(true);
 }
Пример #20
0
        private void SetOption(IOptionParser parser, OptionData optionData, string value)
        {
            if (optionData.IsList)
            {
                IList list = optionData.GetList(m_Options);
                SplitList(list, parser.ListSeparator, value);
                return;
            }

            if (optionData.Set)
            {
                throw new OptionAssignedException(value);
            }
            optionData.SetValue(m_Options, value);
        }
Пример #21
0
        private void ParseOptionParameter(IOptionParser parser, OptionData optionData, OptionToken token)
        {
            string argument = null;

            try {
                if (optionData.ExpectsValue)
                {
                    OptionToken argumentToken = parser.GetToken(true);
                    if (argumentToken == null)
                    {
                        OptionDefaultAttribute defaultAttribute = null;
                        if (optionData.Member != null)
                        {
                            defaultAttribute = GetAttribute <OptionDefaultAttribute>(optionData.Member);
                        }
                        if (defaultAttribute == null)
                        {
                            throw new OptionMissingArgumentException(token.ToString(parser));
                        }
                        argument = defaultAttribute.DefaultValue;
                    }
                    else
                    {
                        argument = argumentToken.Value;
                    }
                    SetOption(parser, optionData, argument);
                }
                else
                {
                    // This is a boolean type. We can only set it to true.
                    SetBoolean(optionData, true);
                }

                optionData.Set = true;
            } catch (OptionException) {
                throw;
            } catch (Exception e) {
                string message;
                if (argument == null)
                {
                    message = string.Format("Error parsing option '{0}'", token.ToString(parser));
                    throw new OptionException(message);
                }
                message = string.Format("Wrong format '{0}' given to option {1}", argument, token.ToString(parser));
                throw new OptionFormatException(token.Value, message, e);
            }
        }
Пример #22
0
        public bool Execute(IEnumerable <string> lazyArguments, IOptionParser options)
        {
            var arguments = lazyArguments.ToList();
            var result    = false;

            if (arguments.Count >= 2)
            {
                result = MoveTags(arguments);
            }

            if (result == false)
            {
                _logger.LogWarning("Rename failed");
            }

            return(result);
        }
Пример #23
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            var version = GetVersion();

            _consoleWriter.WriteLine($"{nameof(SortingHat)} {version.Version}");
            _consoleWriter.WriteLine();

            var table = new ConsoleTable(2);

            table.Columns[0].Alignment = ConsoleTableColumnAlignment.Right;

            table.Append("Culture:", version.CultureName ?? "<NULL>");
            table.Append("Current Culture:", CultureInfo.CurrentCulture);

            table.WriteTo(_consoleWriter);
            return(true);
        }
Пример #24
0
        public async Task ExecuteAsync(IEnumerable <string> lazyArguments, IOptionParser options)
        {
            var arguments = lazyArguments.ToList();
            var tags      = arguments.Where(a => a.IsTag()).ToList();
            var files     = arguments.Where(IsFile);

            foreach (var file in _filePathExtractor.FromFilePatterns(files, options.HasOption <RecursiveOption>()).Select(FileFromPath))
            {
                if (tags.Count == 0)
                {
                    _file.Store(file);
                }
                else
                {
                    await TagFile(tags, file);
                }
            }
        }
Пример #25
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            foreach (var tagString in arguments)
            {
                var tag = _tagParser.Parse(tagString);

                if (tag is null)
                {
                    _logger.LogWarning($"Remove tag '{tagString}' failed (parse)");
                }
                else if (tag.Destroy() == false)
                {
                    _logger.LogWarning($"Remove tag '{tagString}' failed (db)");
                }
            }

            return(true);
        }
Пример #26
0
        private bool PrintTagVariables(IOptionParser options)
        {
            var autoTagHandler = _container.Resolve <IAutoTagHandler>();

            _console.Writer.WriteLine("Possible Tag Variables:");
            _console.Writer.WriteLine();
            foreach (var tag in autoTagHandler.AutoTags.OrderBy(tag => tag.AutoTagKey))
            {
                _console.Writer.WriteLine($"* {tag.HumanReadableAutoTagsKey}");
                if (options.HasOption <VerboseOption>())
                {
                    _console.Writer.WriteLine($"=>  {tag.Description}");
                    _console.Writer.WriteLine();
                }
            }

            return(true);
        }
Пример #27
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            var tags  = arguments.Where(a => a.IsTag());
            var files = arguments.Where(IsFile);

            foreach (var file in _filePathExtractor.FromFilePatterns(files, options.HasOption <RecursiveOption>()).Select(FileFromPath))
            {
                foreach (var tag in tags.Select(_tagParser.Parse))
                {
                    if (tag != null)
                    {
                        _logger.LogInformation($"File {file.Path} tagged with {tag.Name}");
                        file.Untag(tag);
                    }
                }
            }

            return(true);
        }
Пример #28
0
        /// <summary>
        /// Returns a <see cref="string" /> that represents this instance.
        /// </summary>
        /// <param name="parser">The parser.</param>
        /// <returns>A <see cref="string" /> that represents this instance.</returns>
        /// <remarks>
        /// This method differs that the format of the string can change depending on
        /// the parser being used.
        /// </remarks>
        public virtual string ToString(IOptionParser parser)
        {
            switch (Token)
            {
            case OptionTokenKind.ShortOption:
                return(parser.ShortOptionPrefix + Value);

            case OptionTokenKind.LongOption:
                return(parser.LongOptionPrefix + Value);

            case OptionTokenKind.Argument:
                return(Value);

            case OptionTokenKind.Value:
                return(Value);

            default:
                return(Value);
            }
        }
Пример #29
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            var result = false;

            if (arguments.Count() == 2)
            {
                result = RenameTag(arguments);
            }
            else
            {
                _logger.LogWarning("rename tag has exactly two arguments, the tag to rename, and a new name: hat rename-tag :tag new_name");
                _consoleWriter.WriteLine("rename tag has exactly two arguments, the tag to rename, and a new name: hat rename-tag :tag new_name");
            }

            if (result == false)
            {
                _logger.LogWarning("Rename failed");
            }

            return(result);
        }
Пример #30
0
        public bool Execute(IEnumerable <string> arguments, IOptionParser options)
        {
            foreach (var filePath in _filePathExtractor.FromFilePatterns(arguments, options.HasOption <RecursiveOption>()))
            {
                _consoleWriter.WriteLine();
                _consoleWriter.WriteLine($"File: {filePath}");

                var file = _newFile();

                file.LoadByPathFromDb(filePath);
                if (file.Hash == null)
                {
                    _consoleWriter.WriteLine("File not in index!");
                }
                else
                {
                    _consoleWriter.WriteLine($"CreatedAt (oldest): {file.CreatedAt}");
                    _consoleWriter.WriteLine($"File Size: {file.Size}");
                    _consoleWriter.WriteLine($"File Hash: {file.Hash.Result}");

                    foreach (var tag in file.GetTags().Result)
                    {
                        _consoleWriter.WriteLine($"Tag: {tag.FullName}");
                    }

                    foreach (var name in file.GetNames().Result)
                    {
                        _consoleWriter.WriteLine($"Name: {name}");
                    }

                    foreach (var path in file.GetPaths().Result)
                    {
                        _consoleWriter.WriteLine($"Path: {path}");
                    }
                }
            }

            return(true);
        }