diff --git a/Clipboard.cs b/Clipboard.cs index 0476f8b..0f79dcd 100644 --- a/Clipboard.cs +++ b/Clipboard.cs @@ -5,17 +5,21 @@ namespace WinHaste // https://stackoverflow.com/questions/44205260/net-core-copy-to-clipboard public static class Clipboard { - public static void Copy(string text) + public static bool Copy(string text) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { $"echo {text} | clip".Bat(); + return true; } if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { $"echo \"{text}\" | pbcopy".Bash(); + return true; } + + return false; } } } \ No newline at end of file diff --git a/Parameters.cs b/Parameters.cs index ddcdd31..d15a169 100644 --- a/Parameters.cs +++ b/Parameters.cs @@ -37,23 +37,13 @@ public Parameters(string[] args) public ParseResult Parse() { - if (_args.Length == 0) - { - return ParseResult.Success; - } - - if (_args.Length > 2) - return ParseResult.BadArgs; - bool pathProvided = false; - if (_args.Length > 1) + if (_args.Length == 0) { - Url = ParseUrl(_args[0]); - FilePath = _args[1]; - pathProvided = true; + Url = DEFAULT_URL; } - else + else if (_args.Length == 1) { Url = ParseUrl(_args[0]); @@ -64,6 +54,16 @@ public ParseResult Parse() pathProvided = true; } } + else if (_args.Length == 2) + { + Url = ParseUrl(_args[0]); + FilePath = _args[1]; + pathProvided = true; + } + else + { + return ParseResult.BadArgs; + } return Url == null ? ParseResult.BadUrl : !File.Exists(FilePath) && pathProvided diff --git a/Program.cs b/Program.cs index 2969615..1b323e2 100644 --- a/Program.cs +++ b/Program.cs @@ -41,8 +41,10 @@ static async Task Main(string[] args) } string hasteUrl = String.Concat(parameters.Url, "/", match.Groups["key"]); - Clipboard.Copy(hasteUrl); - Console.WriteLine($"Haste URL: {hasteUrl} (copied to clipboard){Environment.NewLine}", hasteUrl); + + string copyMessage = Clipboard.Copy(hasteUrl) ? " (copied to clipboard)" : string.Empty; + + Console.WriteLine($"Haste URL: {hasteUrl}{copyMessage}{Environment.NewLine}", hasteUrl); } } diff --git a/Properties/PublishProfiles/linux.pubxml b/Properties/PublishProfiles/linux.pubxml new file mode 100644 index 0000000..4dcb1ae --- /dev/null +++ b/Properties/PublishProfiles/linux.pubxml @@ -0,0 +1,16 @@ + + + + + FileSystem + Release + Any CPU + netcoreapp2.1 + bin\Release\netcoreapp2.1\linux\publish\ + linux-x64 + true + <_IsPortable>false + + \ No newline at end of file diff --git a/Properties/PublishProfiles/osx.pubxml b/Properties/PublishProfiles/osx.pubxml new file mode 100644 index 0000000..1c58b25 --- /dev/null +++ b/Properties/PublishProfiles/osx.pubxml @@ -0,0 +1,16 @@ + + + + + FileSystem + Release + Any CPU + netcoreapp2.1 + bin\Release\netcoreapp2.1\osx\publish\ + osx.10.12-x64 + true + <_IsPortable>false + + \ No newline at end of file diff --git a/Properties/PublishProfiles/win.pubxml b/Properties/PublishProfiles/win.pubxml new file mode 100644 index 0000000..283f7fd --- /dev/null +++ b/Properties/PublishProfiles/win.pubxml @@ -0,0 +1,16 @@ + + + + + FileSystem + Release + Any CPU + netcoreapp2.1 + bin\Release\netcoreapp2.1\win\publish\ + win7-x64 + true + <_IsPortable>false + + \ No newline at end of file diff --git a/WinHaste.csproj b/WinHaste.csproj index f9475cd..45cbe1d 100644 --- a/WinHaste.csproj +++ b/WinHaste.csproj @@ -1,8 +1,9 @@ - + Exe netcoreapp2.1 false latest + win7-x64;osx.10.12-x64;linux-x64 \ No newline at end of file diff --git a/publish-all.cmd b/publish-all.cmd new file mode 100644 index 0000000..9a292ba --- /dev/null +++ b/publish-all.cmd @@ -0,0 +1,3 @@ + dotnet publish -c Release -r linux-x64 --self-contained + dotnet publish -c Release -r win7-x64 --self-contained + dotnet publish -c Release -r osx.10.12-x64 --self-contained \ No newline at end of file