From e7720ccc4e111f242f1dab577d7d8da313052a4f Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Fri, 19 May 2017 16:47:32 +0100 Subject: [PATCH] small refactor --- src/dotnet-sharpcompress/InfoOptions.cs | 42 +++++++++++++++++++++++ src/dotnet-sharpcompress/Program.cs | 44 +------------------------ 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/dotnet-sharpcompress/InfoOptions.cs b/src/dotnet-sharpcompress/InfoOptions.cs index d91b0281..b3a3d5f9 100644 --- a/src/dotnet-sharpcompress/InfoOptions.cs +++ b/src/dotnet-sharpcompress/InfoOptions.cs @@ -1,5 +1,8 @@ +using System; using System.Collections.Generic; +using System.IO; using CommandLine; +using SharpCompress.Archives; namespace SharpCompress { @@ -11,5 +14,44 @@ namespace SharpCompress [Option('e', HelpText = "Show Archive Entry Information")] public bool ShowEntries { get; set; } + + public int Process() + { + foreach (var s in Path) + { + if (File.Exists(s)) + { + Console.WriteLine($"=== Archive: {s}"); + try + { + using (var archive = ArchiveFactory.Open(File.OpenRead(s))) + { + Console.WriteLine($"Archive Type: {archive.Type}"); + + Console.WriteLine($"Size: {archive.TotalSize}"); + Console.WriteLine($"Uncompressed Size: {archive.TotalUncompressSize}"); + + if (ShowEntries) + { + foreach (var archiveEntry in archive.Entries) + { + Console.WriteLine($"\tEntry: {archiveEntry.Key}"); + } + } + } + } + catch (Exception) + { + Console.WriteLine("Archive Type is unknown."); + } + } + else + { + Console.WriteLine($"{s} does not exist"); + return 1; + } + } + return 0; + } } } \ No newline at end of file diff --git a/src/dotnet-sharpcompress/Program.cs b/src/dotnet-sharpcompress/Program.cs index 94a005f7..d2c94c38 100644 --- a/src/dotnet-sharpcompress/Program.cs +++ b/src/dotnet-sharpcompress/Program.cs @@ -1,7 +1,4 @@ -using System; -using System.IO; using CommandLine; -using SharpCompress.Archives; namespace SharpCompress { @@ -11,49 +8,10 @@ namespace SharpCompress { return Parser.Default.ParseArguments(args) .MapResult( - (InfoOptions opts) => Info(opts), + (InfoOptions opts) => opts.Process(), (ExtractOptions opts) => Extract(opts), errs => 1); } - - public static int Info(InfoOptions options) - { - foreach (var s in options.Path) - { - if (File.Exists(s)) - { - Console.WriteLine($"=== Archive: {s}"); - try - { - using (var archive = ArchiveFactory.Open(File.OpenRead(s))) - { - Console.WriteLine($"Archive Type: {archive.Type}"); - - Console.WriteLine($"Size: {archive.TotalSize}"); - Console.WriteLine($"Uncompressed Size: {archive.TotalUncompressSize}"); - - if (options.ShowEntries) - { - foreach (var archiveEntry in archive.Entries) - { - Console.WriteLine($"\tEntry: {archiveEntry.Key}"); - } - } - } - } - catch (Exception e) - { - Console.WriteLine("Archive Type is unknown."); - } - } - else - { - Console.WriteLine($"{s} does not exist"); - return 1; - } - } - return 0; - } public static int Extract(ExtractOptions options) {