Skip to content

Commit

Permalink
Updated document generation program
Browse files Browse the repository at this point in the history
  • Loading branch information
crisfervil committed Nov 1, 2017
1 parent 4eaede4 commit d78fd91
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 304 deletions.
285 changes: 0 additions & 285 deletions commands.json

This file was deleted.

10 changes: 10 additions & 0 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ Name | Description
-l, --log-level | Sets the current logging output. Can be Debug, Info, Error


## Examples
Export all the existing accounts to an Accounts.xml file
```
xrm --file Accounts.xml --entity account --connection DEV
```
Export all the existing contacts returned by a fetch query to the contacts.xml file
```
xrm --file Contacts.xml --connection DEV --config-file ContactsQuery.xml
```

# import

Imports information from a file to Dynamics
Expand Down
43 changes: 35 additions & 8 deletions src/DocGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CommandInfo
public string Summary { get; set; }
public string Remarks { get; set; }
public List<CommandOption> Options { get; set; }
public List<string> Examples { get; set; }
public List<CommandExample> Examples { get; set; }
public string ApplicationAlias { get; set; }
}

Expand All @@ -37,6 +37,20 @@ class CommandOption
public string Remarks { get; set; }
}

class CommandExample
{
public string ApplicationAlias { get; set; }
public string HelpText { get; set; }
public List<CommandExampleParam> Values { get; set; }
}

class CommandExampleParam
{
public bool IsDefault { get; set; }
public string OptionLongName { get; set; }
public string ParamValue { get; set; }
}

static void Main(string[] args)
{

Expand All @@ -62,13 +76,13 @@ static void Main(string[] args)

// get the properties with the option attribute
var options = optionType.GetProperties().Where(x => x.GetCustomAttribute(typeof(OptionAttribute)) != null);
var optionAttrs = options.Select(x => x.GetCustomAttribute<OptionAttribute>());
var optionAttrs = options.Select(x => new { Property=x, OptionAttribute= x.GetCustomAttribute<OptionAttribute>() });

foreach (var optionAttr in optionAttrs)
foreach (var commandOption in optionAttrs)
{
if (!optionAttr.Hidden)
if (!commandOption.OptionAttribute.Hidden)
{
commandInfo.Options.Add(new CommandOption() { ShortName=optionAttr.ShortName, LongName=optionAttr.LongName, HelpText=optionAttr.HelpText });
commandInfo.Options.Add(new CommandOption() { ShortName=commandOption.OptionAttribute.ShortName, LongName=commandOption.OptionAttribute.LongName, HelpText=commandOption.OptionAttribute.HelpText });
}
}

Expand All @@ -77,16 +91,29 @@ static void Main(string[] args)
if(usageProperties.Count > 0)
{
var usageProperty = usageProperties[0];
commandInfo.Examples = new List<string>();

var usageAttr = usageProperty.GetCustomAttribute<UsageAttribute>();
commandInfo.ApplicationAlias = usageAttr.ApplicationAlias;
commandInfo.Examples = new List<CommandExample>();

var commandExamples = (IEnumerable<Example>)usageProperty.GetMethod.Invoke(null, null);

foreach (var example in commandExamples)
{
commandInfo.Examples.Add(example.HelpText);
var commandExample = new CommandExample() { ApplicationAlias = commandInfo.ApplicationAlias, Values = new List<CommandExampleParam>(), HelpText = example.HelpText };
foreach (var optionAttr in optionAttrs)
{
// get the property vaue
//System.Diagnostics.Debugger.Break();
var propValue = optionAttr.Property.GetMethod.Invoke(example.Sample, null);
if (propValue != null)
{
var isDefault = optionAttr.OptionAttribute.Default != null && optionAttr.OptionAttribute.Default.ToString() == propValue.ToString();
commandExample.Values.Add(new CommandExampleParam { OptionLongName = optionAttr.OptionAttribute.LongName, ParamValue = propValue.ToString(), IsDefault=isDefault });
}
}
commandInfo.Examples.Add(commandExample);
}

}

doc.Commands.Add(commandInfo);
Expand Down
Loading

0 comments on commit d78fd91

Please sign in to comment.