New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dotnet tool #234

Closed
wants to merge 3 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+43 −43
Diff settings

Always

Just for now

Viewing a subset of changes. View all

small refactor

  • Loading branch information...
adamhathcock committed May 19, 2017
commit e7720ccc4e111f242f1dab577d7d8da313052a4f
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using CommandLine;
using SharpCompress.Archives;
namespace SharpCompress
{
@@ -11,5 +14,44 @@ public class InfoOptions
[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;
}
}
}
@@ -1,7 +1,4 @@
using System;
using System.IO;
using CommandLine;
using SharpCompress.Archives;
namespace SharpCompress
{
@@ -11,49 +8,10 @@ public static int Main(string[] args)
{
return Parser.Default.ParseArguments<InfoOptions, ExtractOptions>(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)
{
ProTip! Use n and p to navigate between commits in a pull request.