Skip to content

Commit

Permalink
Renamed Cmdlets
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinvanhunen committed Oct 29, 2016
1 parent d2d995e commit 6b3136c
Show file tree
Hide file tree
Showing 366 changed files with 2,254 additions and 1,612 deletions.
11 changes: 4 additions & 7 deletions CmdletHelpGenerator/CmdletInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ public class CmdletInfo
public string OutputTypeDescription { get; set; }
public string OutputTypeLink { get; set; }

public string FullCommand
{
get
{
return string.Format("{0}-{1}", Verb, Noun);
}
}
public List<string> Aliases { get; set; }

public string FullCommand => $"{Verb}-{Noun}";

public string Category { get; set; }

Expand All @@ -41,6 +37,7 @@ public CmdletInfo(string verb, string noun)
Noun = noun;
Parameters = new List<CmdletParameterInfo>();
Syntaxes = new List<CmdletSyntax>();
Aliases = new List<string>();
}
}
}
122 changes: 112 additions & 10 deletions CmdletHelpGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,43 @@ static void Main(string[] args)
{
var cmdlets = new List<CmdletInfo>();
var inFile = args[0];

var outFile = args[1];
var toc = new List<CmdletInfo>();

// Specify an additional (third) parameter pointing to the Solution folder to generate Markdown. The markdown
// will be created in the Documentation folder underneath the solution folder.
bool generateMarkdown = false;
string solutionDir = null;
string spVersion = "Online";

if (args.Length > 2)
{
solutionDir = args[2];
var configuration = args[2];
solutionDir = args[3];
generateMarkdown = true;
switch (configuration)
{
case "debug":
case "release":
{
spVersion = "Online";
break;
}
case "debug15":
case "release15":
{
spVersion = "2013";
break;

}
case "debug16":
case "release16":
{
spVersion = "2016";
break;
}
}
}


Expand All @@ -48,7 +74,10 @@ static void Main(string[] args)

var assembly = Assembly.LoadFrom(inFile);
var types = assembly.GetTypes();
// System.Diagnostics.Debugger.Launch();
// System.Diagnostics.Debugger.Launch();

var cmdletsToExport = new List<string>();
var aliasesToCreate = new List<KeyValuePair<string, string>>();

foreach (var t in types)
{
Expand All @@ -68,6 +97,7 @@ static void Main(string[] args)
Type outputType = null;
var outputTypeLink = string.Empty;
var outputTypeDescription = string.Empty;
var aliases = new List<string>();

// Get info from attributes
foreach (var attr in attrs)
Expand All @@ -79,6 +109,12 @@ static void Main(string[] args)
noun = a.NounName;

}
if (attr is CmdletAliasAttribute)
{
var a = (CmdletAliasAttribute)attr;
aliases.Add(a.Alias);
}

if (attr is CmdletHelpAttribute)
{
var a = (CmdletHelpAttribute)attr;
Expand Down Expand Up @@ -113,13 +149,26 @@ static void Main(string[] args)
cmdletInfo.OutputType = outputType;
cmdletInfo.OutputTypeLink = outputTypeLink;
cmdletInfo.OutputTypeDescription = outputTypeDescription;
cmdletInfo.Aliases = aliases;

if (!string.IsNullOrEmpty(cmdletInfo.Verb) && !string.IsNullOrEmpty(cmdletInfo.Noun))
{
cmdletsToExport.Add(cmdletInfo.FullCommand);
}

if (cmdletInfo.Aliases.Any())
{
foreach (var alias in cmdletInfo.Aliases)
{
aliasesToCreate.Add(new KeyValuePair<string, string>(cmdletInfo.FullCommand, alias));
}
}
// Build XElement for command
var commandElement = new XElement(command + "command", mamlNsAttr, commandNsAttr, devNsAttr);
var detailsElement = new XElement(command + "details");
commandElement.Add(detailsElement);

detailsElement.Add(new XElement(command + "name", string.Format("{0}-{1}", verb, noun)));
detailsElement.Add(new XElement(command + "name", $"{verb}-{noun}"));
detailsElement.Add(new XElement(maml + "description", new XElement(maml + "para", description)));
detailsElement.Add(new XElement(maml + "copyright", new XElement(maml + "para", copyright)));
detailsElement.Add(new XElement(command + "verb", verb));
Expand Down Expand Up @@ -368,23 +417,75 @@ static void Main(string[] args)
CreateReadme(toc, solutionDir);
}

DirectoryInfo di = new DirectoryInfo(string.Format("{0}\\Documentation", solutionDir));
DirectoryInfo di = new DirectoryInfo($"{solutionDir}\\Documentation");
var mdFiles = di.GetFiles("*.md");

// Clean up old MD files
foreach (var mdFile in mdFiles)
{
if (mdFile.Name.ToLowerInvariant() != "readme.md")
{
var index = toc.FindIndex(t => string.Format("{0}{1}.md", t.Verb, t.Noun) == mdFile.Name);
var index = toc.FindIndex(t => $"{t.Verb}{t.Noun}.md" == mdFile.Name);
if (index == -1)
{
mdFile.Delete();
}
}
}

// Generate PSM1 file
var aliasesToExport = new List<string>();
var psm1Path = $"{new FileInfo(inFile).Directory}\\ModuleFiles\\SharePointPnPPowerShell{spVersion}.psm1";


if (aliasesToCreate.Any())
{
var aliasBuilder = new StringBuilder();

foreach (var alias in aliasesToCreate.Where(a => !string.IsNullOrEmpty(a.Key)).OrderBy(a => a.Key))
{
var aliasLine = $"Set-Alias -Name {alias.Value} -Value {alias.Key}";
aliasBuilder.AppendLine(aliasLine);
aliasesToExport.Add(alias.Value);
}
Console.WriteLine($"Writing {psm1Path}");
File.WriteAllText(psm1Path, aliasBuilder.ToString());
}
else
{
File.WriteAllText(psm1Path, "");
}

// Create Module Manifest

var psd1Path = $"{new FileInfo(inFile).Directory}\\ModuleFiles\\SharePointPnPPowerShell{spVersion}.psd1";
var cmdletsToExportString = string.Join(",", cmdletsToExport.Select(x => "'" + x + "'"));
var aliasesToExportString = string.Join(",", aliasesToExport.Select(x => "'" + x + "'"));
WriteModuleManifest(psd1Path, spVersion, cmdletsToExportString, aliasesToExportString);
}

private static void WriteModuleManifest(string path, string version, string cmdletsToExport, string aliasesToExport)
{
var manifest = $@"@{{
ModuleToProcess = 'SharePointPnPPowerShell{version}.psm1'
NestedModules = 'SharePointPnP.PowerShell.{version}.Commands.dll'
ModuleVersion = '2.9.1611.0'
Description = 'SharePoint Patterns and Practices PowerShell Cmdlets for SharePoint {version}'
GUID = '8f1147be-a8e4-4bd2-a705-841d5334edc0'
Author = 'SharePoint Patterns and Practices'
CompanyName = 'SharePoint Patterns and Practices'
DotNetFrameworkVersion = '4.5'
ProcessorArchitecture = 'None'
FunctionsToExport = '*'
CmdletsToExport = {cmdletsToExport}
VariablesToExport = '*'
AliasesToExport = {aliasesToExport}
FormatsToProcess = 'SharePointPnP.PowerShell.{version}.Commands.Format.ps1xml'
}}";

Console.WriteLine($"Writing {path}");
File.WriteAllText(path, manifest, Encoding.UTF8);
}
private static List<FieldInfo> GetFields(Type t)
{
var fieldInfoList = new List<FieldInfo>();
Expand All @@ -405,7 +506,7 @@ private static void CreateReadme(List<CmdletInfo> toc, string solutionDir)
var newMd = string.Empty;

// Create the readme.md
var readmePath = string.Format("{0}\\Documentation\\readme.md", solutionDir);
var readmePath = $"{solutionDir}\\Documentation\\readme.md";
if (System.IO.File.Exists(readmePath))
{
originalMd = System.IO.File.ReadAllText(readmePath);
Expand All @@ -415,7 +516,7 @@ private static void CreateReadme(List<CmdletInfo> toc, string solutionDir)

docBuilder.AppendFormat("# Cmdlet Documentation #{0}", Environment.NewLine);
docBuilder.AppendFormat("Below you can find a list of all the available cmdlets. Many commands provide built-in help and examples. Retrieve the detailed help with {0}", Environment.NewLine);
docBuilder.AppendFormat("{0}```powershell{0}Get-Help Connect-SPOnline -Detailed{0}```{0}{0}", Environment.NewLine);
docBuilder.AppendFormat("{0}```powershell{0}Get-Help Connect-PnPOnline -Detailed{0}```{0}{0}", Environment.NewLine);

// Get all unique categories
var categories = toc.Select(c => c.Category).Distinct();
Expand Down Expand Up @@ -452,9 +553,10 @@ private static void GenerateMarkDown(List<CmdletInfo> toc, string solutionDir, L
var originalMd = string.Empty;
var newMd = string.Empty;


if (!string.IsNullOrEmpty(cmdletInfo.Verb) && !string.IsNullOrEmpty(cmdletInfo.Noun))
{
string mdFilePath = string.Format("{0}\\Documentation\\{1}{2}.md", solutionDir, cmdletInfo.Verb, cmdletInfo.Noun);
string mdFilePath = $"{solutionDir}\\Documentation\\{cmdletInfo.Verb}{cmdletInfo.Noun}.md";
toc.Add(cmdletInfo);

if (System.IO.File.Exists(mdFilePath))
Expand Down Expand Up @@ -486,7 +588,7 @@ private static void GenerateMarkDown(List<CmdletInfo> toc, string solutionDir, L
}
else
{
syntaxText.Append(new string(' ',cmdletLength + 1));
syntaxText.Append(new string(' ', cmdletLength + 1));
}
if (!par.Required)
{
Expand Down Expand Up @@ -556,7 +658,7 @@ private static void GenerateMarkDown(List<CmdletInfo> toc, string solutionDir, L

newMd = docBuilder.ToString();

DiffMatchPatch.diff_match_patch dmp = new DiffMatchPatch.diff_match_patch();
var dmp = new DiffMatchPatch.diff_match_patch();

var diffResults = dmp.diff_main(newMd, originalMd);

Expand Down
5 changes: 3 additions & 2 deletions Commands/Admin/GetTenantSite.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if !ONPREMISES
using System;
using System.ComponentModel;
using System.Linq;
using System.Management.Automation;
Expand All @@ -11,7 +12,8 @@
namespace SharePointPnP.PowerShell.Commands
{

[Cmdlet(VerbsCommon.Get, "SPOTenantSite", SupportsShouldProcess = true)]
[Cmdlet(VerbsCommon.Get, "PnPTenantSite", SupportsShouldProcess = true)]
[CmdletAlias("Get-SPOTenantSite")]
[CmdletHelp(@"Office365 only: Uses the tenant API to retrieve site information.",
Category = CmdletHelpCategory.TenantAdmin,
OutputType = typeof(Microsoft.Online.SharePoint.TenantAdministration.SiteProperties),
Expand Down Expand Up @@ -77,6 +79,5 @@ protected override void ExecuteCmdlet()
}
}
}

}
#endif
32 changes: 21 additions & 11 deletions Commands/Admin/GetTimeZoneId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@

namespace SharePointPnP.PowerShell.Commands
{
[Cmdlet(VerbsCommon.Get, "SPOTimeZoneId")]
[CmdletHelp("Returns a time zone ID",
Category = CmdletHelpCategory.TenantAdmin,
OutputType = typeof(IEnumerable<Zone>),
OutputTypeDescription = "Returns a list of matching zones. Use the ID property of the object for use in New-SPOTenantSite")]
[CmdletExample(Code = @"PS:> Get-SPOTimeZoneId",Remarks = @"This will return all time zone IDs in use by Office 365.", SortOrder = 1)]
[CmdletExample(Code = @"PS:> Get-SPOTimeZoneId -Match Stockholm", Remarks = @"This will return the time zone IDs for Stockholm", SortOrder = 2)]
[Cmdlet(VerbsCommon.Get, "PnPTimeZoneId")]
[CmdletAlias("Get-SPOTimeZoneId")]
[CmdletHelp("Returns a time zone ID",
Category = CmdletHelpCategory.TenantAdmin,
OutputType = typeof(IEnumerable<Zone>),
OutputTypeDescription =
"Returns a list of matching zones. Use the ID property of the object for use in New-SPOTenantSite")]
[CmdletExample(Code = @"PS:> Get-SPOTimeZoneId",
Remarks = @"This will return all time zone IDs in use by Office 365.", SortOrder = 1)]
[CmdletExample(Code = @"PS:> Get-SPOTimeZoneId -Match Stockholm",
Remarks = @"This will return the time zone IDs for Stockholm", SortOrder = 2)]
public class GetTimeZoneId : PSCmdlet
{
[Parameter(Mandatory = false, Position=0, HelpMessage = "A string to search for like 'Stockholm'")]
public string Match;
[Parameter(Mandatory = false, Position = 0, HelpMessage = "A string to search for like 'Stockholm'")]
public
string Match;

protected override void ProcessRecord()
{
Expand All @@ -34,7 +39,11 @@ private IEnumerable<Zone> FindZone(string match)
{
var zones = AllZones();

var results = zones.Where(x => x.Description.ToLower().IndexOf(match.ToLower(), StringComparison.Ordinal) > -1 || x.Identifier.ToLower().Contains(match.ToLower()));
var results =
zones.Where(
x =>
x.Description.ToLower().IndexOf(match.ToLower(), StringComparison.Ordinal) > -1 ||
x.Identifier.ToLower().Contains(match.ToLower()));

return results;
}
Expand All @@ -50,7 +59,8 @@ public IEnumerable<Zone> AllZones()
identifier = identifier.Replace("PLUS", "+").Replace("MINUS", "-");
if (identifier.Length > 3)
{
identifier = identifier.Substring(0, identifier.Length - 2) + ":" + identifier.Substring(identifier.Length - 2, 2);
identifier = identifier.Substring(0, identifier.Length - 2) + ":" +
identifier.Substring(identifier.Length - 2, 2);
}

description = description.Substring(description.IndexOf('_') + 1).Replace("_", " ");
Expand Down
4 changes: 3 additions & 1 deletion Commands/Admin/GetWebTemplates.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#if !ONPREMISES
using System;
using SharePointPnP.PowerShell.CmdletHelpAttributes;
using Microsoft.SharePoint.Client;
using SharePointPnP.PowerShell.Commands.Base;
using System.Management.Automation;

namespace SharePointPnP.PowerShell.Commands
{
[Cmdlet(VerbsCommon.Get, "SPOWebTemplates")]
[Cmdlet(VerbsCommon.Get, "PnPWebTemplates")]
[CmdletAlias("Get-SPOWebTemplates")]
[CmdletHelp(@"Office365 only: Returns the available web templates.",
Category = CmdletHelpCategory.TenantAdmin,
OutputType=typeof(Microsoft.Online.SharePoint.TenantAdministration.SPOTenantWebTemplateCollection),
Expand Down
11 changes: 6 additions & 5 deletions Commands/Admin/NewTenantSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

namespace SharePointPnP.PowerShell.Commands
{
[Cmdlet(VerbsCommon.New, "SPOTenantSite")]
[Cmdlet(VerbsCommon.New, "PnPTenantSite")]
[CmdletAlias("New-SPOTenantSite")]
[CmdletHelp("Creates a new site collection for the current tenant",
DetailedDescription = @"The New-SPOTenantSite cmdlet creates a new site collection for the current company. However, creating a new SharePoint
DetailedDescription = @"The New-PnPTenantSite cmdlet creates a new site collection for the current company. However, creating a new SharePoint
Online site collection fails if a deleted site with the same URL exists in the Recycle Bin. If you want to use this command for an on-premises farm, please refer to http://blogs.msdn.com/b/vesku/archive/2014/06/09/provisioning-site-collections-using-sp-app-model-in-on-premises-with-just-csom.aspx ",
Category = CmdletHelpCategory.TenantAdmin)]
[CmdletExample(
Code = @"PS:> New-SPOTenantSite -Title Contoso -Url https://tenant.sharepoint.com/sites/contoso -Owner user@example.org -TimeZone 4",
Code = @"PS:> New-PnPTenantSite -Title Contoso -Url https://tenant.sharepoint.com/sites/contoso -Owner user@example.org -TimeZone 4",
Remarks = @"This will add a site collection with the title 'Contoso', the url 'https://tenant.sharepoint.com/sites/contoso', the timezone 'UTC+01:00' and the owner 'user@example.org'", SortOrder = 1)]
[CmdletRelatedLink(
Text ="Locale IDs",
Expand Down Expand Up @@ -40,10 +41,10 @@ public class NewTenantSite : SPOAdminCmdlet
[Parameter(Mandatory = false, HelpMessage = @"Specifies the language of this site collection. For more information, see Locale IDs Assigned by Microsoft: http://go.microsoft.com/fwlink/p/?LinkId=242911Id=242911.")]
public uint Lcid = 1033;

[Parameter(Mandatory = false, HelpMessage = @"Specifies the site collection template type. Use the Get-SPOWebTemplate cmdlet to get the list of valid templates. If no template is specified, one can be added later. The Template and LocaleId parameters must be a valid combination as returned from the Get-SPOnlineWebTemplate cmdlet.")]
[Parameter(Mandatory = false, HelpMessage = @"Specifies the site collection template type. Use the Get-SPOWebTemplate cmdlet to get the list of valid templates. If no template is specified, one can be added later. The Template and LocaleId parameters must be a valid combination as returned from the Get-PnPWebTemplates cmdlet.")]
public string Template = "STS#0";

[Parameter(Mandatory = true, HelpMessage = "Use Get-SPOTimeZoneId to retrieve possible timezone values")]
[Parameter(Mandatory = true, HelpMessage = "Use Get-PnPTimeZoneId to retrieve possible timezone values")]
public int TimeZone;

[Parameter(Mandatory = false, HelpMessage = @"Specifies the quota for this site collection in Sandboxed Solutions units. This value must not exceed the company's aggregate available Sandboxed Solutions quota. The default value is 0. For more information, see Resource Usage Limits on Sandboxed Solutions in SharePoint 2010 : http://msdn.microsoft.com/en-us/library/gg615462.aspx.")]
Expand Down
Loading

0 comments on commit 6b3136c

Please sign in to comment.