Skip to content

Commit

Permalink
Added --adbc-version option
Browse files Browse the repository at this point in the history
  • Loading branch information
italankin committed Feb 11, 2020
1 parent e28be0d commit c8a5750
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ $ adb -s $SELECTED_DEVICE shell input text password
$ adb -s $SELECTED_DEVICE shell input keyevent ENTER
```

## Print version

Run `adbc` with `--adbc-version` option:

```sh
$ adbc --adbc-version
adbc version: 1.0.0
Using adb path: /home/user/android-sdk/platform-tools/adb
Android Debug Bridge version 1.0.41
Version 29.0.5-5949299
Installed as /home/user/android-sdk/platform-tools/adb
```

# Building

`adbc` requires `ncurses` library.
Expand Down
19 changes: 19 additions & 0 deletions adbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <string.h>
#include <ncurses.h>

#define VERSION "1.0.0"

#define MAX_LINE_LEN 512
#define ADB_LOCATION "/platform-tools/adb"

Expand All @@ -19,6 +21,7 @@ struct device_list {

char* ADB = NULL;

int print_version();
char* get_sdk_path();
void read_adb_path();
char* get_adb_command(char* command);
Expand All @@ -30,6 +33,10 @@ int exec_command(char* id, int argc, char* argv[]);
int main(int argc, char* argv[]) {
read_adb_path();

if (argc == 2 && strcmp(argv[1], "--adbc-version") == 0) {
return print_version();
}

struct device_list devices = get_devices();

if (devices.count == 0) {
Expand All @@ -47,6 +54,18 @@ int main(int argc, char* argv[]) {
return exec_command(chosen->id, argc, argv);
}

int print_version() {
printf("adbc version: %s\n", VERSION);
if (strcmp(ADB, "adb") == 0) {
printf("Android SDK not found\n");
return 1;
} else {
printf("Using adb path: %s\n", ADB);
char* adb_version = get_adb_command("--version");
return system(adb_version);
}
}

char* get_sdk_path() {
char* android_home = getenv("ANDROID_HOME");
if (android_home != NULL && strlen(android_home) > 0) {
Expand Down

0 comments on commit c8a5750

Please sign in to comment.