diff --git a/IpfsCli/CommandBase.cs b/IpfsCli/CommandBase.cs index e9516116..05d990aa 100644 --- a/IpfsCli/CommandBase.cs +++ b/IpfsCli/CommandBase.cs @@ -1,4 +1,5 @@ using McMaster.Extensions.CommandLineUtils; +using McMaster.Extensions.CommandLineUtils.HelpText; using System; using System.Collections.Generic; using System.Text; @@ -6,8 +7,8 @@ namespace Ipfs.Cli { - [HelpOption("--help")] - abstract class CommandBase + + abstract class CommandBase : DefaultHelpTextGenerator { protected virtual Task OnExecute(CommandLineApplication app) { diff --git a/IpfsCli/Commands/RepoCommand.cs b/IpfsCli/Commands/RepoCommand.cs index 79b2d82d..4c161a62 100644 --- a/IpfsCli/Commands/RepoCommand.cs +++ b/IpfsCli/Commands/RepoCommand.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.IO; using System.Text; using System.Threading.Tasks; @@ -86,10 +87,15 @@ class RepoMigrateCommand : CommandBase { RepoCommand Parent { get; set; } - [Argument(0, "version", "The version number of the repository")] + [Argument(0, "version", "The version # of the repository")] [Required] public int Version { get; set; } + protected override void GenerateFooter(CommandLineApplication application, TextWriter output) + { + output.WriteLine("Versions:"); + } + protected override async Task OnExecute(CommandLineApplication app) { // TODO: Add option --pass diff --git a/IpfsCli/IpfsCli.csproj b/IpfsCli/IpfsCli.csproj index 93f3e524..bfa016f8 100644 --- a/IpfsCli/IpfsCli.csproj +++ b/IpfsCli/IpfsCli.csproj @@ -16,7 +16,7 @@ - + diff --git a/IpfsCli/Program.cs b/IpfsCli/Program.cs index 8050efc7..01ea138a 100644 --- a/IpfsCli/Program.cs +++ b/IpfsCli/Program.cs @@ -20,6 +20,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using McMaster.Extensions.CommandLineUtils.HelpText; namespace Ipfs.Cli { @@ -59,6 +60,7 @@ class Program : CommandBase public static int Main(string[] args) { + var exitCode = -1; var startTime = DateTime.Now; // Need to setup common.logging early. @@ -73,7 +75,10 @@ public static int Main(string[] args) try { - CommandLineApplication.Execute(args); + var app = new CommandLineApplication(); + app.HelpTextGenerator = new Help(); + app.Conventions.UseDefaultConventions(); + exitCode = app.Execute(args); } catch (Exception e) { @@ -86,13 +91,13 @@ public static int Main(string[] args) Console.WriteLine(e.StackTrace); } } - return 1; + exitCode = 1; } var took = DateTime.Now - startTime; //Console.Write($"Took {took.TotalSeconds} seconds."); - return 0; + return exitCode; } [Option("--api ", Description = "Use a specific API instance")] @@ -174,6 +179,26 @@ public int Output(CommandLineApplication app, T data, Action t private static string GetVersion() => typeof(Program).Assembly.GetCustomAttribute().InformationalVersion; + + /// + /// Generate help text by using the default help text generated. + /// + /// + /// Allows the footer to be command specific. + /// + class Help : DefaultHelpTextGenerator + { + + /// + /// Use command specific footer. + /// + /// + /// + protected override void GenerateFooter(CommandLineApplication application, TextWriter output) + { + // TODO + } + } } } diff --git a/IpfsCli/Properties/launchSettings.json b/IpfsCli/Properties/launchSettings.json index 020551fd..89caeeee 100644 --- a/IpfsCli/Properties/launchSettings.json +++ b/IpfsCli/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "IpfsCli": { "commandName": "Project", - "commandLineArgs": "--help" + "commandLineArgs": "repo migrate --help" } } } \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 41529299..0557b0b8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -63,7 +63,7 @@ after_test: - docfx doc\docfx.json --logLevel Warning --warningsAsErrors - 7z a -tzip docs.zip doc\_site - appveyor PushArtifact docs.zip - - if defined git_token npm install gh-pages -g + - if defined git_token npm install gh-pages@2.0 -g - if defined git_token gh-pages -d doc\_site -m "new docs %GitVersion_FullSemVer%" artifacts: diff --git a/src/CoreApi/ObjectApi.cs b/src/CoreApi/ObjectApi.cs index 6b44fc71..38331776 100644 --- a/src/CoreApi/ObjectApi.cs +++ b/src/CoreApi/ObjectApi.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -49,8 +50,16 @@ public ObjectApi(IpfsEngine ipfs) public async Task> LinksAsync(Cid id, CancellationToken cancel = default(CancellationToken)) { - var node = await GetAsync(id, cancel).ConfigureAwait(false); - return node.Links; + var block = await ipfs.Block.GetAsync(id, cancel).ConfigureAwait(false); + try + { + var node = new DagNode(block.DataStream); + return node.Links; + } + catch + { + return Enumerable.Empty(); + } } public Task NewAsync(string template = null, CancellationToken cancel = default(CancellationToken)) diff --git a/test/CoreApi/ObjectApiTest.cs b/test/CoreApi/ObjectApiTest.cs index bbf16aee..46cca662 100644 --- a/test/CoreApi/ObjectApiTest.cs +++ b/test/CoreApi/ObjectApiTest.cs @@ -158,5 +158,35 @@ public async Task Get_Inlinefile() } } + [TestMethod] + public async Task Links_InlineCid() + { + var original = ipfs.Options.Block.AllowInlineCid; + try + { + ipfs.Options.Block.AllowInlineCid = true; + + var node = await ipfs.FileSystem.AddTextAsync("hiya"); + Assert.AreEqual(1, node.Id.Version); + Assert.IsTrue(node.Id.Hash.IsIdentityHash); + + var links = await ipfs.Object.LinksAsync(node.Id); + Assert.AreEqual(0, links.Count()); + } + finally + { + ipfs.Options.Block.AllowInlineCid = original; + } + } + + [TestMethod] + public async Task Links_RawCid() + { + var blob = new byte[2048]; + var cid = await ipfs.Block.PutAsync(blob, contentType: "raw"); + + var links = await ipfs.Object.LinksAsync(cid); + Assert.AreEqual(0, links.Count()); + } } } \ No newline at end of file