File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . ComponentModel . DataAnnotations ;
4+ using System . IO ;
5+ using System . Linq ;
6+ using Dotnetcnblog . TagHandlers ;
7+ using Dotnetcnblog . Utils ;
8+ using McMaster . Extensions . CommandLineUtils ;
9+ using Console = Colorful . Console ;
10+
11+ namespace Dotnetcnblog . Command
12+ {
13+ [ Command ( Name = "upload" , Description = "上传单个图片" ) ]
14+ public class CommandUploadImg : ICommand
15+ {
16+ private static readonly Dictionary < string , string > ReplaceDic = new Dictionary < string , string > ( ) ;
17+
18+
19+ [ Option ( "-f|--file" , Description = "需要上传的图片路径" ) ]
20+ [ Required ]
21+ public string FilePath { get ; set ; }
22+
23+ public int OnExecute ( CommandLineApplication app )
24+ {
25+ if ( app . Options . Count == 1 && app . Options [ 0 ] . ShortName == "h" )
26+ {
27+ app . ShowHelp ( ) ;
28+ }
29+
30+ Execute ( CommandContextStore . Get ( ) ) ;
31+ return 0 ;
32+ }
33+
34+ public void Execute ( CommandContext context )
35+ {
36+ try
37+ {
38+ if ( ! File . Exists ( FilePath ) )
39+ {
40+ ConsoleHelper . PrintError ( $ "文件不存在:{ FilePath } ") ;
41+ }
42+ else
43+ {
44+
45+ var imgUrl = ImageUploadHelper . Upload ( FilePath ) ;
46+ ConsoleHelper . PrintMsg ( $ "{ FilePath } 上传成功. { imgUrl } ") ;
47+
48+ }
49+ }
50+ catch ( Exception e )
51+ {
52+ ConsoleHelper . PrintError ( e . Message ) ;
53+ }
54+ }
55+ }
56+ }
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ namespace Dotnetcnblog
1515 [ Subcommand ( typeof ( CommandReset ) ) ]
1616 [ Subcommand ( typeof ( CommandSetConfig ) ) ]
1717 [ Subcommand ( typeof ( CommandProcessFile ) ) ]
18+ [ Subcommand ( typeof ( CommandUploadImg ) ) ]
1819 class Program
1920 {
2021 private const string CfgFileName = "dotnet-cnblog.config.json" ;
You can’t perform that action at this time.
0 commit comments