|
| 1 | +# AShell |
| 2 | +Perfect for Android and Mac os! |
| 3 | + |
| 4 | +Utilize the power of lowlevel unix based os commands.<br/> |
| 5 | +Just define unix commands with a shell executor model with simple java annotations and let AShell do the heavy work. |
| 6 | +Add result listeners to handle command outputs and shell state.<br/> |
| 7 | +Customize the shell build process and run as root, if root access is available on system. |
| 8 | + |
| 9 | +# Gradle |
| 10 | +#### Step 1. Add the JitPack repository to your build file |
| 11 | +```groovy |
| 12 | +allprojects { |
| 13 | + repositories { |
| 14 | + ... |
| 15 | + maven { url 'https://jitpack.io' } |
| 16 | + } |
| 17 | +} |
| 18 | +``` |
| 19 | +#### Step 2. Add the dependency |
| 20 | +```groovy |
| 21 | +dependencies { |
| 22 | + compile 'com.github.manneohlund:ashell:1.0.0' // Coming soon! |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +# Usage |
| 27 | +### Shell model setup |
| 28 | + |
| 29 | +```java |
| 30 | +public interface ShellModel { |
| 31 | + |
| 32 | + @LS("{options} {paths}") |
| 33 | + void ls(@Param("options") String options, @Param("paths") String... paths); |
| 34 | + |
| 35 | + @CP("{in} {out}") |
| 36 | + void copy(@Paths @Param("in") String in, @Paths @Param("out") String out); |
| 37 | + |
| 38 | + @MV("{in} {out}") |
| 39 | + void rename(@Paths @Param("in") String in, @Paths @Param("out") String out); |
| 40 | + |
| 41 | + @CAT("{path}") |
| 42 | + void cat(@Param("path") String path); |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +### Basic usage |
| 47 | + |
| 48 | +```java |
| 49 | + ShellFactory shellFactory = new ShellFactory.Builder() |
| 50 | + // Supply builder with listeners and customizations |
| 51 | + .build(); |
| 52 | + |
| 53 | + ShellModel shellModel = shellFactory.create(ShellModel.class); |
| 54 | + |
| 55 | + // List files in a folder |
| 56 | + shellModel.ls("-l -a", "/system"); |
| 57 | + |
| 58 | + // Copy an image |
| 59 | + shellModel.cp("/system/image.jpg", "/system/image2.jpg"); |
| 60 | + |
| 61 | + // Copy an image |
| 62 | + shellModel.mv("/system/image.jpg", "/system/subfolder/image.jpg"); |
| 63 | + |
| 64 | + // Read content in a text file |
| 65 | + shellModel.cat("/system/some_file.txt"); |
| 66 | +``` |
| 67 | + |
| 68 | +### Add shell result listeners |
| 69 | +```java |
| 70 | + OnShellResultListener listener = new OnShellResultListener<String>() { |
| 71 | + @Override |
| 72 | + public boolean onShellResult(String result) { |
| 73 | + System.out.println(result); |
| 74 | + return false; // Must always return false if you didn't handle the command |
| 75 | + } |
| 76 | + }; |
| 77 | + |
| 78 | + OnShellErrorResultListener errorListener = new OnShellErrorResultListener() { |
| 79 | + @Override |
| 80 | + public boolean onShellErrorResult(String result) { |
| 81 | + System.err.println(result); |
| 82 | + return false; // Must always return false if you didn't handle the command |
| 83 | + } |
| 84 | + }; |
| 85 | + |
| 86 | + ShellFactory shellFactory = new ShellFactory.Builder() |
| 87 | + .setOnShellListener(listener) |
| 88 | + .setOnShellErrorListener(errorListener) |
| 89 | + .build(); |
| 90 | +``` |
| 91 | + |
| 92 | +### Advanced usage |
| 93 | +```java |
| 94 | +Coming soon! |
| 95 | +``` |
| 96 | + |
| 97 | +License |
| 98 | +------- |
| 99 | + |
| 100 | + Copyright 2017 Manne Öhlund |
| 101 | + |
| 102 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 103 | + you may not use this file except in compliance with the License. |
| 104 | + You may obtain a copy of the License at |
| 105 | + |
| 106 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 107 | + |
| 108 | + Unless required by applicable law or agreed to in writing, software |
| 109 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 110 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 111 | + See the License for the specific language governing permissions and |
| 112 | + limitations under the License. |
0 commit comments