diff --git a/BoxCLI/BoxCLIInfo.cs b/BoxCLI/BoxCLIInfo.cs index c60867b0..7c3c697d 100644 --- a/BoxCLI/BoxCLIInfo.cs +++ b/BoxCLI/BoxCLIInfo.cs @@ -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"; } } \ No newline at end of file diff --git a/BoxCLI/Commands/FolderCommand.cs b/BoxCLI/Commands/FolderCommand.cs index 1dc668ba..898fa290 100644 --- a/BoxCLI/Commands/FolderCommand.cs +++ b/BoxCLI/Commands/FolderCommand.cs @@ -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); diff --git a/BoxCLI/Commands/FolderSubCommands/FolderRenameCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderRenameCommand.cs new file mode 100644 index 00000000..5a3c0bb6 --- /dev/null +++ b/BoxCLI/Commands/FolderSubCommands/FolderRenameCommand.cs @@ -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 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); + } + } +} diff --git a/BoxCLI/Commands/FolderSubCommands/FolderSubCommandFactory.cs b/BoxCLI/Commands/FolderSubCommands/FolderSubCommandFactory.cs index c9c280fc..eb497098 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderSubCommandFactory.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderSubCommandFactory.cs @@ -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."); diff --git a/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs index 84920022..3f8e98f4 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs @@ -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); diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..1716a831 --- /dev/null +++ b/CHANGELOG.md @@ -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! \ No newline at end of file diff --git a/README.md b/README.md index 4bb3b4a5..71d9bc12 100644 --- a/README.md +++ b/README.md @@ -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)