#!/usr/bin/expect -f
# Do you accept the license 'android-sdk-license-5be876d5'

# Usage example:
#  ./accept-licenses "android update sdk --no-ui --all --filter build-tools" "android-sdk-license-5be876d5"

set timeout 1800
set cmd [lindex $argv 0]
set licenses [lindex $argv 1]

spawn {*}$cmd
expect {
  -regexp "Do you accept the license '($licenses)'.*" {
        exp_send "y\r"
        exp_continue
  }
  "Do you accept the license '*-license-*'*" {
        exp_send "y\r"
        exp_continue
  }
  eof
}
