File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1
1
use clap:: * ;
2
+ use std:: path:: Path ;
2
3
3
4
pub fn build_app ( ) -> App < ' static , ' static > {
4
- App :: new ( "haste" )
5
+ let mut app = App :: new ( "haste" )
5
6
. version ( crate_version ! ( ) )
6
7
. about ( crate_description ! ( ) )
7
8
. after_help (
8
9
"If you invoke the subcommand without an argument or pipe, it will open interactively. \
9
10
Type text there and press Ctrl-d on unix or Ctrl-z on Windows to exit and paste the content. \
10
11
\n \n Report issues at https://github.com/Ay-355/haste-cli"
11
12
)
13
+ . setting ( AppSettings :: DisableHelpSubcommand )
12
14
. arg (
13
15
Arg :: with_name ( "FILE" )
14
16
. help ( "The file you want to paste. Use '-' or nothing for standard input." )
@@ -32,4 +34,12 @@ pub fn build_app() -> App<'static, 'static> {
32
34
. short ( "r" )
33
35
. long ( "raw" )
34
36
)
37
+
38
+ if Path :: new ( "view" ) . exists ( ) {
39
+ app
40
+ } else {
41
+ . subcommand (
42
+ SubCommand :: with_name ( "view" )
43
+ . about ( "Get the contents of a paste." )
44
+ ) }
35
45
}
Original file line number Diff line number Diff line change @@ -11,3 +11,11 @@ pub fn upload_content(content: String) -> Result<String, ureq::Error> {
11
11
. into_json ( ) ?;
12
12
Ok ( json. key )
13
13
}
14
+
15
+ pub fn get_content ( id : & str ) -> Result < String , ureq:: Error > {
16
+ let content =
17
+ ureq:: get ( format ! ( "https://www.toptal.com/developers/hastebin/raw/{}" , & id) . as_str ( ) )
18
+ . call ( ) ?
19
+ . into_string ( ) ?;
20
+ Ok ( content)
21
+ }
You can’t perform that action at this time.
0 commit comments