Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/dotnet-cnblogs/Command/CommandUploadImg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using Dotnetcnblog.TagHandlers;
using Dotnetcnblog.Utils;
using McMaster.Extensions.CommandLineUtils;
using Console = Colorful.Console;

namespace Dotnetcnblog.Command
{
[Command(Name = "upload", Description = "上传单个图片")]
public class CommandUploadImg : ICommand
{
private static readonly Dictionary<string, string> ReplaceDic = new Dictionary<string, string>();


[Option("-f|--file", Description = "需要上传的图片路径")]
[Required]
public string FilePath { get; set; }

public int OnExecute(CommandLineApplication app)
{
if (app.Options.Count == 1 && app.Options[0].ShortName == "h")
{
app.ShowHelp();
}

Execute(CommandContextStore.Get());
return 0;
}

public void Execute(CommandContext context)
{
try
{
if (!File.Exists(FilePath))
{
ConsoleHelper.PrintError($"文件不存在:{FilePath}");
}
else
{

var imgUrl = ImageUploadHelper.Upload(FilePath);
ConsoleHelper.PrintMsg($"{FilePath} 上传成功. {imgUrl}");

}
}
catch (Exception e)
{
ConsoleHelper.PrintError(e.Message);
}
}
}
}
1 change: 1 addition & 0 deletions src/dotnet-cnblogs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Dotnetcnblog
[Subcommand(typeof(CommandReset))]
[Subcommand(typeof(CommandSetConfig))]
[Subcommand(typeof(CommandProcessFile))]
[Subcommand(typeof(CommandUploadImg))]
class Program
{
private const string CfgFileName = "dotnet-cnblog.config.json";
Expand Down