Skip to content

Commit

Permalink
Convert Clone to NDesk.Options.
Browse files Browse the repository at this point in the history
  • Loading branch information
spraints committed Jan 30, 2012
1 parent dcd6dc6 commit 817df46
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
7 changes: 3 additions & 4 deletions GitTfs/Commands/Clone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.IO;
using System.Linq;
using NDesk.Options;
using CommandLine.OptParse;
using Sep.Git.Tfs.Core;
using StructureMap;
using Sep.Git.Tfs.Util;
Expand All @@ -29,12 +28,12 @@ public Clone(Globals globals, Fetch fetch, Init init)

public OptionSet OptionSet
{
get { return new OptionSet(); }
get { return init.OptionSet.Merge(fetch.OptionSet); }
}

public IEnumerable<IOptionResults> ExtraOptions
public IEnumerable<CommandLine.OptParse.IOptionResults> ExtraOptions
{
get { return this.MakeNestedOptionResults(init, fetch); }
get { return this.MakeNestedOptionResults(); }
}

public int Run(string tfsUrl, string tfsRepositoryPath)
Expand Down
35 changes: 29 additions & 6 deletions GitTfs/Commands/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CommandLine.OptParse;
using NDesk.Options;

namespace Sep.Git.Tfs.Commands
{
public static class Helpers
{
public static OptionSet Merge(this OptionSet options, params OptionSet[] others)
{
var merged = new MergableOptionSet();
merged.Merge(options);
foreach(var other in others)
merged.Merge(other);
return merged;
}

class MergableOptionSet : OptionSet
{
public void Merge(OptionSet other)
{
foreach(var option in other)
{
if(!Contains(GetKeyForItem(option)))
{
Add(option);
}
}
}
}

[Obsolete("... migrating to NDesk.Options ...")]
public static IEnumerable<IOptionResults> MakeNestedOptionResults(this GitTfsCommand command, params object[] optionsObjectsOrCommands)
public static IEnumerable<CommandLine.OptParse.IOptionResults> MakeNestedOptionResults(this GitTfsCommand command, params object[] optionsObjectsOrCommands)
{
foreach(var obj in optionsObjectsOrCommands)
{
Expand All @@ -18,15 +41,15 @@ public static IEnumerable<IOptionResults> MakeNestedOptionResults(this GitTfsCom
{
yield return option;
}
yield return new PropertyFieldParserHelper(obj);
yield return new CommandLine.OptParse.PropertyFieldParserHelper(obj);
}
else if(obj is IOptionResults)
else if(obj is CommandLine.OptParse.IOptionResults)
{
yield return (IOptionResults) obj;
yield return (CommandLine.OptParse.IOptionResults) obj;
}
else
{
yield return new PropertyFieldParserHelper(obj);
yield return new CommandLine.OptParse.PropertyFieldParserHelper(obj);
}
}
}
Expand Down

0 comments on commit 817df46

Please sign in to comment.