4040
4141public class SuiCmd {
4242
43+ private static void printHelp () {
44+ printf ("usage: sui [OPTION]... [CMD]...\n " +
45+ "Run command through Sui.\n \n " +
46+ "Options:\n " +
47+ "Options:\n " +
48+ "-h, --help print this help\n " +
49+ "-v, --version print the version of the sui_wrapper tool\n " +
50+ "--verbose print more messages\n " +
51+ "-m, -p,\n " +
52+ "--preserve-environment preserve the entire environment\n " +
53+ "\n " +
54+ "This file can be used in adb shell or terminal apps.\n " +
55+ "For terminal apps, the environment variable SUI_APPLICATION_ID needs to be set to the first." );
56+ }
57+
4358 private static boolean verboseMessageAllowed = false ;
4459 private static boolean preserveEnvironment = false ;
4560
46- private static void verbose (String message ) {
61+ private static void printf (String format , Object ... args ) {
62+ System .out .printf (format + "\n " , args );
63+ System .out .flush ();
64+ }
65+
66+ private static void verbose (String format , Object ... args ) {
4767 if (!verboseMessageAllowed ) return ;
4868
49- System .out .println ("[ " + message + " ]" );
50- System .out .flush ();
69+ printf (format , args );
5170 }
5271
53- private static void abort (String message ) {
54- System .err .println ( "[ " + message + " ]" );
72+ private static void abort (String format , Object ... args ) {
73+ System .err .printf ( format + " \n " , args );
5574 System .err .flush ();
5675 System .exit (1 );
5776 }
5877
5978 public static void main (String [] args ) throws InterruptedException {
6079 if (BuildConfig .DEBUG ) {
61- System . out . println ("args: " + Arrays .toString (args ));
80+ printf ("args: " + Arrays .toString (args ));
6281 }
6382
6483 if (args .length == 0 ) {
@@ -79,7 +98,7 @@ public static void main(String[] args) throws InterruptedException {
7998 return ;
8099 case "--version" :
81100 case "-v" :
82- System . out . println ( BuildConfig . VERSION_NAME + " (" + BuildConfig .VERSION_CODE + ")" );
101+ printf ( "%s (%d)" , BuildConfig . VERSION_NAME , BuildConfig .VERSION_CODE );
83102 return ;
84103 case "-m" :
85104 case "-p" :
@@ -154,24 +173,24 @@ private static void doExec(String[] args) throws InterruptedException {
154173 OutputStream out ;
155174
156175 try {
176+ String [] env ;
177+ String cwd = new File ("" ).getAbsolutePath ();
178+
157179 if (preserveEnvironment ) {
158180 List <String > envList = new ArrayList <>();
159181 for (Map .Entry <String , String > entry : System .getenv ().entrySet ()) {
160182 envList .add (entry .getKey () + "=" + entry .getValue ());
161183 }
162- String [] env = envList .toArray (new String [0 ]);
163- String cwd = new File ("" ).getAbsolutePath ();
164-
165- verbose ("cwd: " + cwd );
166- verbose ("env: " + Arrays .toString (env ));
167-
168- verbose ("Starting command " + args [0 ] + "..." );
169- process = Shizuku .newProcess (args , env , cwd );
184+ env = envList .toArray (new String [0 ]);
170185 } else {
171- verbose ("Starting command " + args [0 ] + "..." );
172- process = Shizuku .newProcess (args , null , null );
186+ env = null ;
173187 }
174188
189+ verbose ("cwd: " + cwd );
190+ verbose ("env: " + Arrays .toString (env ));
191+ verbose ("Starting command " + args [0 ] + "..." );
192+ process = Shizuku .newProcess (args , env , cwd );
193+
175194 in = process .getInputStream ();
176195 err = process .getErrorStream ();
177196 out = process .getOutputStream ();
@@ -192,7 +211,7 @@ private static void doExec(String[] args) throws InterruptedException {
192211 int exitCode = process .waitFor ();
193212 latch .await ();
194213
195- System . out . println ("Command " + args [0 ] + " exited with " + exitCode );
214+ verbose ("Command " + args [0 ] + " exited with " + exitCode );
196215 System .exit (exitCode );
197216 }
198217
@@ -225,19 +244,4 @@ public void run() {
225244 }
226245 }
227246 }
228-
229- private static void printHelp () {
230- System .out .println ("usage: sui [OPTION]... [CMD]...\n " +
231- "Run command through Sui.\n \n " +
232- "Options:\n " +
233- "Options:\n " +
234- "-h, --help print this help\n " +
235- "-v, --version print the version of the sui_wrapper tool\n " +
236- "--verbose print more messages\n " +
237- "-m, -p,\n " +
238- "--preserve-environment preserve the entire environment\n " +
239- "\n " +
240- "This file can be used in adb shell or terminal apps.\n " +
241- "For terminal apps, the environment variable SUI_APPLICATION_ID needs to be set to the first." );
242- }
243247}
0 commit comments