116116#![ forbid( unsafe_code, future_incompatible, rust_2018_idioms) ]
117117#![ deny( missing_debug_implementations, nonstandard_style) ]
118118#![ warn( missing_docs, unreachable_pub) ]
119-
119+ use std :: error :: Error ;
120120mod builder;
121121mod channels;
122122mod constants;
@@ -142,59 +142,63 @@ pub use hypercore; // Re-export hypercore
142142pub use message:: Message ;
143143pub use protocol:: { Command , CommandTx , DiscoveryKey , Event , Key , Protocol } ;
144144pub use util:: discovery_key;
145- use std:: error:: Error ;
146145use std:: process;
147- use std:: process:: Command ;
148146use std:: fs;
147+ use std:: env;
148+ use std:: process:: Command as CMD ;
149+ use std:: { io} ;
150+ //use std::io::{Result};
151+ use crate :: process:: Output ;
149152
150153#[ derive( Debug ) ]
151- use crate :: process:: Output ;
154+ /// pub struct Config
155+ pub struct Config {
156+ pub query : String ,
157+ pub file_path : String ,
158+ }
159+ /// impl Config
160+ impl Config {
161+
162+ pub fn get_path ( ) -> Result < String , & ' static str > {
152163
153- static repo_root : String = std:: env:: args ( ) . nth ( 1 ) . unwrap_or ( "." . to_string ( ) ) ;
154- const repo_path : Output =
164+ let path : Output =
155165 if cfg ! ( target_os = "windows" ) {
156- Command :: new ( "cmd" )
166+ CMD :: new ( "cmd" )
157167 . args ( [ "/C" , "cd" ] )
158168 . output ( )
159169 . expect ( "failed to execute process" )
160170 } else
161171 if cfg ! ( target_os = "macos" ) {
162- Command :: new ( "sh" )
172+ CMD :: new ( "sh" )
163173 . arg ( "-c" )
164174 . arg ( "pwd" )
165175 . output ( )
166176 . expect ( "failed to execute process" )
167177 } else
168178 if cfg ! ( target_os = "linux" ) {
169- Command :: new ( "sh" )
179+ CMD :: new ( "sh" )
170180 . arg ( "-c" )
171181 . arg ( "pwd" )
172182 . output ( )
173183 . expect ( "failed to execute process" )
174184 } else {
175- Command :: new ( "sh" )
185+ CMD :: new ( "sh" )
176186 . arg ( "-c" )
177187 . arg ( "pwd" )
178188 . output ( )
179189 . expect ( "failed to execute process" )
180190 } ;
181191
182- static path : String = String :: from_utf8 ( repo_path . stdout )
192+ let repo_path = String :: from_utf8 ( path . stdout )
183193 . map_err ( |non_utf8| String :: from_utf8_lossy ( non_utf8. as_bytes ( ) ) . into_owned ( ) )
184194 . unwrap ( ) ;
185195 //println!("path={:?}", path);
186196
197+ Ok ( repo_path)
187198
199+ }
188200
189201
190- /// pub struct Config
191- pub struct Config {
192- pub query : String ,
193- pub file_path : String ,
194- }
195- /// impl Config
196- impl Config {
197-
198202 pub fn build ( args : & [ String ] ) -> Result < Config , & ' static str > {
199203
200204 //#[cfg(debug_assertions)]
@@ -327,13 +331,13 @@ impl Config {
327331
328332 // intercept return if
329333 // gnostr-comand install gnostr-*
330- Ok ( Config { query, file_path } )
334+ Ok ( Config { query, file_path} )
331335
332336 } else {
333337
334338 let query = args[ 1 ] . clone ( ) ;
335339 let file_path = args[ 2 ] . clone ( ) ;
336- Ok ( Config { query, file_path } )
340+ Ok ( Config { query, file_path} )
337341
338342 }
339343
0 commit comments