Skip to content

Commit

Permalink
Merge pull request #51 from box/folders-update-bugs
Browse files Browse the repository at this point in the history
Fixed bug with folders update and added folders rename command. Also …
  • Loading branch information
allenmichael authored Oct 16, 2017
2 parents 30cc735 + e3721fc commit f3177c9
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 3 deletions.
2 changes: 1 addition & 1 deletion BoxCLI/BoxCLIInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class BoxCLIInfo
{
public const string ProductTitle = "Box CLI";

public const string Version = "1.0.0";
public const string Version = "1.0.1";
}
}
1 change: 1 addition & 0 deletions BoxCLI/Commands/FolderCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public override void Configure(CommandLineApplication command)
command.Command(_names.SubCommandNames.Download, _subCommands.CreateSubCommand(_names.SubCommandNames.Download).Configure);
command.Command(_names.SubCommandNames.Upload, _subCommands.CreateSubCommand(_names.SubCommandNames.Upload).Configure);
command.Command(_names.SubCommandNames.ChangeUploadEmail, _subCommands.CreateSubCommand(_names.SubCommandNames.ChangeUploadEmail).Configure);
command.Command(_names.SubCommandNames.Rename, _subCommands.CreateSubCommand(_names.SubCommandNames.Rename).Configure);
command.Command(_names.CommandNames.Metadata, new MetadataCommand(base._boxPlatformBuilder, base._boxHome, this._factory, base._names, BoxType.folder).Configure);
command.Command(_names.CommandNames.Collaborations, new CollaborationOnItemCommand(base._boxPlatformBuilder, base._boxHome, this._factory, base._names, BoxType.folder).Configure);
command.Command(_names.CommandNames.SharedLinks, new SharedLinkCommand(base._boxPlatformBuilder, base._boxHome, this._factory, base._names, BoxType.folder).Configure);
Expand Down
83 changes: 83 additions & 0 deletions BoxCLI/Commands/FolderSubCommands/FolderRenameCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Text;
using BoxCLI.BoxHome;
using BoxCLI.BoxPlatform.Service;
using BoxCLI.CommandUtilities.Globalization;
using Microsoft.Extensions.CommandLineUtils;
using System.Threading.Tasks;
using Box.V2.Models;

namespace BoxCLI.Commands.FolderSubCommands
{
class FolderRenameCommand : FolderSubCommandBase
{
private CommandLineApplication _app;
private IBoxHome _home;
private CommandArgument _folderId;
private CommandArgument _folderName;
private CommandOption _description;
private CommandOption _etag;

public FolderRenameCommand(IBoxPlatformServiceBuilder boxPlatformBuilder, IBoxHome home, LocalizedStringsResource names) : base(boxPlatformBuilder, home, names)
{
_home = home;
}


public override void Configure(CommandLineApplication command)
{
_app = command;
command.Description = "Rename a folder.";
_folderId = command.Argument("folderId",
"Id of folder to rename");
_folderName = command.Argument("fileName",
"New name of file");
_description = command.Option("--description", "Change the folder description", CommandOptionType.SingleValue);
_etag = command.Option("--etag", "Only rename if etag value matches", CommandOptionType.SingleValue);
command.OnExecute(async () =>
{
return await this.Execute();
});
base.Configure(command);
}

protected async override Task<int> Execute()
{
await this.RunRename();
return await base.Execute();
}

protected async Task RunRename()
{
base.CheckForId(this._folderId.Value, this._app);
base.CheckForValue(this._folderName.Value, _app, "A name value is required to rename a folder.");
var boxClient = base.ConfigureBoxClient(base._asUser.Value());
var folderRenameRequest = new BoxFolderRequest()
{
Name = this._folderName.Value,
Id = this._folderId.Value
};

if(this._description.HasValue())
{
folderRenameRequest.Description = this._description.Value();
}
BoxFolder folder;
if(this._etag.HasValue())
{
folder = await boxClient.FoldersManager.UpdateInformationAsync(folderRenameRequest, etag: this._etag.Value());
}
else
{
folder = await boxClient.FoldersManager.UpdateInformationAsync(folderRenameRequest);
}
if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting())
{
base.OutputJson(folder);
return;
}
base.PrintFolder(folder);
}
}
}
4 changes: 4 additions & 0 deletions BoxCLI/Commands/FolderSubCommands/FolderSubCommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public override ISubCommand CreateSubCommand(string commandName)
{
return new FolderUploadCommand(base._boxPlatformBuilder, base._boxHome, base._names);
}
else if (commandName == base._names.SubCommandNames.Rename)
{
return new FolderRenameCommand(base._boxPlatformBuilder, base._boxHome, base._names);
}
else
{
throw new Exception("Command not registered.");
Expand Down
21 changes: 20 additions & 1 deletion BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,26 @@ await this.UpdateFoldersFromFile(this._bulkFilePath.Value(), base._asUser.Value(
{
folderUpdateRequest.Tags = this._tags.Value().Split(',');
}
var updated = await boxClient.FoldersManager.UpdateInformationAsync(folderUpdateRequest);

if (this._name.HasValue())
{
folderUpdateRequest.Name = this._name.Value();
}

if (this._description.HasValue())
{
folderUpdateRequest.Description = this._description.Value();
}

BoxFolder updated;
if (this._etag.HasValue())
{
updated = await boxClient.FoldersManager.UpdateInformationAsync(folderUpdateRequest, etag: this._etag.Value());
}
else
{
updated = await boxClient.FoldersManager.UpdateInformationAsync(folderUpdateRequest);
}
if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting())
{
base.OutputJson(updated);
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

## 1.0.1

- Fixed minor bug preventing --name, --description, and --etag options from working on the `box folders update` command
- Added a `box folders rename` command.

## 1.0.0

- Welcome to the Box CLI!
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Box CLI

## Current Version: 1.0.1
## Prerequisites for Building from Source
* [.Net Core SDK v2.0](https://www.microsoft.com/net/core)

Expand Down

0 comments on commit f3177c9

Please sign in to comment.