From 5391d0f4ee0fdd1f43adbb9190c04c47fe17d30b Mon Sep 17 00:00:00 2001
From: Ian Douglas Scott <ian@iandouglasscott.com>
Date: Fri, 23 Jun 2017 16:15:45 -0700
Subject: [PATCH] Allow specifying target at runtime

The cookbook could be used to build for multiple architectures, if that
is ever supported.
---
 src/bin/pkg.rs | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/bin/pkg.rs b/src/bin/pkg.rs
index 8b0c397..65ea06e 100644
--- a/src/bin/pkg.rs
+++ b/src/bin/pkg.rs
@@ -87,10 +87,11 @@ fn upgrade(repo: Repo) -> io::Result<()> {
 }
 
 fn main() {
-    let repo = Repo::new(env!("TARGET"));
-
     let matches = App::new("pkg")
-        .subcommand(SubCommand::with_name("clean")
+        .arg(Arg::with_name("target")
+             .long("target")
+             .takes_value(true)
+        ).subcommand(SubCommand::with_name("clean")
             .arg(Arg::with_name("package")
                  .multiple(true)
                  .required(true)
@@ -128,6 +129,13 @@ fn main() {
         ).subcommand(SubCommand::with_name("upgrade")
         ).get_matches();
 
+    let target = matches.value_of("target")
+        .or(option_env!("TARGET"))
+        .expect(concat!("pkg was not compiled with a target, ",
+                        "and --target was not specified"));
+
+    let repo = Repo::new(target);
+
     match matches.subcommand() {
         ("clean", Some(m)) => {
             for package in m.values_of("package").unwrap() {
-- 
GitLab