Added -Task CLI command which will allow uploading with specific task setting

Example usage: "Image.png" -Task "Upload to Imgur"
This commit is contained in:
Jaex 2015-09-20 11:01:36 +03:00
parent 5f50b194dd
commit c7ed2ad73e
4 changed files with 38 additions and 8 deletions

View file

@ -23,6 +23,8 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3) #endregion License Information (GPL v3)
using System;
namespace ShareX.HelpersLib namespace ShareX.HelpersLib
{ {
public class CLICommand public class CLICommand
@ -37,6 +39,11 @@ public CLICommand(string command = null, string parameter = null)
Parameter = parameter; Parameter = parameter;
} }
public bool CheckCommand(string command)
{
return !string.IsNullOrEmpty(Command) && Command.Equals(command, StringComparison.InvariantCultureIgnoreCase);
}
public override string ToString() public override string ToString()
{ {
string text = string.Format("Command: \"{0}\"", Command); string text = string.Format("Command: \"{0}\"", Command);

View file

@ -46,7 +46,7 @@ public bool CheckCommands(List<CLICommand> commands)
{ {
foreach (string text in Commands) foreach (string text in Commands)
{ {
if (command.Command.Equals(text, StringComparison.InvariantCultureIgnoreCase)) if (command.CheckCommand(text))
{ {
ExecuteAction(command.Parameter); ExecuteAction(command.Parameter);
return true; return true;

View file

@ -139,9 +139,9 @@ public bool IsCommandExist(params string[] commands)
command1 = command1.Substring(1); command1 = command1.Substring(1);
} }
foreach (CLICommand command2 in Commands.Where(x => x != null && x.IsCommand && !string.IsNullOrEmpty(x.Command))) foreach (CLICommand command2 in Commands.Where(x => x != null && x.IsCommand))
{ {
if (command1.Equals(command2.Command, StringComparison.InvariantCultureIgnoreCase)) if (command2.CheckCommand(command1))
{ {
return true; return true;
} }
@ -154,7 +154,7 @@ public bool IsCommandExist(params string[] commands)
public string GetParameter(string command) public string GetParameter(string command)
{ {
CLICommand cliCommand = Commands.Find(x => command.Equals(x.Command, StringComparison.InvariantCultureIgnoreCase)); CLICommand cliCommand = Commands.Find(x => x.CheckCommand(command));
if (cliCommand != null) if (cliCommand != null)
{ {

View file

@ -719,6 +719,8 @@ private void ForceClose()
public void UseCommandLineArgs(List<CLICommand> commands) public void UseCommandLineArgs(List<CLICommand> commands)
{ {
TaskSettings taskSettings = FindCLITask(commands);
foreach (CLICommand command in commands) foreach (CLICommand command in commands)
{ {
DebugHelper.WriteLine("CommandLine: " + command.Command); DebugHelper.WriteLine("CommandLine: " + command.Command);
@ -730,11 +732,11 @@ public void UseCommandLineArgs(List<CLICommand> commands)
if (URLHelpers.IsValidURLRegex(command.Command)) if (URLHelpers.IsValidURLRegex(command.Command))
{ {
UploadManager.DownloadAndUploadFile(command.Command); UploadManager.DownloadAndUploadFile(command.Command, taskSettings);
} }
else else
{ {
UploadManager.UploadFile(command.Command); UploadManager.UploadFile(command.Command, taskSettings);
} }
} }
} }
@ -743,7 +745,7 @@ private bool CheckCLIHotkey(CLICommand command)
{ {
foreach (HotkeyType job in Helpers.GetEnums<HotkeyType>()) foreach (HotkeyType job in Helpers.GetEnums<HotkeyType>())
{ {
if (command.Command.Equals(job.ToString(), StringComparison.InvariantCultureIgnoreCase)) if (command.CheckCommand(job.ToString()))
{ {
ExecuteJob(job); ExecuteJob(job);
return true; return true;
@ -755,7 +757,7 @@ private bool CheckCLIHotkey(CLICommand command)
private bool CheckCLIWorkflow(CLICommand command) private bool CheckCLIWorkflow(CLICommand command)
{ {
if (command.Command.Equals("workflow", StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(command.Parameter) && Program.HotkeysConfig != null) if (Program.HotkeysConfig != null && command.CheckCommand("workflow") && !string.IsNullOrEmpty(command.Parameter))
{ {
foreach (HotkeySettings hotkeySetting in Program.HotkeysConfig.Hotkeys) foreach (HotkeySettings hotkeySetting in Program.HotkeysConfig.Hotkeys)
{ {
@ -773,6 +775,27 @@ private bool CheckCLIWorkflow(CLICommand command)
return false; return false;
} }
private TaskSettings FindCLITask(List<CLICommand> commands)
{
if (Program.HotkeysConfig != null)
{
CLICommand command = commands.FirstOrDefault(x => x.CheckCommand("task") && !string.IsNullOrEmpty(x.Parameter));
if (command != null)
{
foreach (HotkeySettings hotkeySetting in Program.HotkeysConfig.Hotkeys)
{
if (command.Parameter == hotkeySetting.TaskSettings.ToString())
{
return hotkeySetting.TaskSettings;
}
}
}
}
return null;
}
private WorkerTask[] GetCurrentTasks() private WorkerTask[] GetCurrentTasks()
{ {
if (lvUploads.SelectedItems.Count > 0) if (lvUploads.SelectedItems.Count > 0)