소스 검색

fix publish install.sh template: GIST_ID/IMAGE swap, build-arg line continuations

Alexander Korolev 1 개월 전
부모
커밋
e75f2ba7a2
1개의 변경된 파일과 8개의 추가작업 그리고 12개의 파일을 삭제
  1. 8 12
      src/publish.rs

+ 8 - 12
src/publish.rs

@@ -297,31 +297,27 @@ fn render_install_sh(
 ) -> String {
     let args = versions
         .iter()
-        .map(|(k, v)| format!("  --build-arg {}={}\n", shq(k), shq(v)))
+        .map(|(k, v)| format!("  --build-arg {}={} \\\n", shq(k), shq(v)))
         .collect::<String>();
-    let gid = gist_id.unwrap_or("'          '");
+    let gid = gist_id
+        .map(shq)
+        .unwrap_or_else(|| "'          '".to_string());
+    let image_q = shq(image);
     format!(
         "#!/usr/bin/env bash\n\
          # Build {image}. Run from this folder, or set GIST_ID and run from\n\
          # anywhere to clone the published gist into /tmp first.\n\
          # Usage: curl -fsSL <raw-url>/install.sh | bash   (after publishing as a gist)\n\
          set -euo pipefail\n\n\
-         GIST_ID={}  # fill in after `sm121 publish --gist`\n\
+         GIST_ID={gid}  # filled in by `sm121 publish --gist`\n\
          DIR=/tmp/{recipe_name}-build\n\
-         IMAGE={}\n\n\
+         IMAGE={image_q}\n\n\
          HERE=\"$(cd \"$(dirname \"$0\")\" && pwd)\"\n\
          if [ -f \"$HERE/Dockerfile\" ]; then\n  SRC=\"$HERE\"\n\
          else\n  rm -rf \"$DIR\"; git clone -q \"https://gist.github.com/${{GIST_ID}}.git\" \"$DIR\"; SRC=\"$DIR\"\n\
          fi\n\n\
-         docker build -t \"$IMAGE\" \\\n{}\"$SRC\"\n\
+         docker build -t \"$IMAGE\" \\\n{args}\"$SRC\"\n\
          echo \"built: $IMAGE — see run.sh\"\n",
-        shq(image),
-        gid,
-        if args.is_empty() {
-            String::new()
-        } else {
-            format!(" \\\n{args}")
-        },
     )
 }