Skip to content

Commit 164ebec

Browse files
committed
Run post-install scripts by default only if the CLI is interactive
This should prevent CI-based runs to block waiting for user interaction.
1 parent f56d39f commit 164ebec

File tree

5 files changed

+66
-20
lines changed

5 files changed

+66
-20
lines changed

Diff for: cli/core/install.go

+32-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/arduino/arduino-cli/cli/instance"
2626
"github.com/arduino/arduino-cli/cli/output"
2727
"github.com/arduino/arduino-cli/commands/core"
28+
"github.com/arduino/arduino-cli/configuration"
2829
rpc "github.com/arduino/arduino-cli/rpc/commands"
2930
"github.com/sirupsen/logrus"
3031
"github.com/spf13/cobra"
@@ -42,14 +43,42 @@ func initInstallCommand() *cobra.Command {
4243
Args: cobra.MinimumNArgs(1),
4344
Run: runInstallCommand,
4445
}
45-
installCommand.Flags().BoolVar(&installFlags.skipPostInstall, "skip-post-install", false, "Do not run post-install scripts.")
46+
addPostInstallFlagsToCommand(installCommand)
4647
return installCommand
4748
}
4849

49-
var installFlags struct {
50+
var postInstallFlags struct {
51+
runPostInstall bool
5052
skipPostInstall bool
5153
}
5254

55+
func addPostInstallFlagsToCommand(cmd *cobra.Command) {
56+
cmd.Flags().BoolVar(&postInstallFlags.runPostInstall, "run-post-install", false, "Force run of post-install scripts (if the CLI is not running interactively).")
57+
cmd.Flags().BoolVar(&postInstallFlags.skipPostInstall, "skip-post-install", false, "Force skip of post-install scripts (if the CLI is running interactively).")
58+
}
59+
60+
func detectSkipPostInstallValue() bool {
61+
if postInstallFlags.runPostInstall && postInstallFlags.skipPostInstall {
62+
feedback.Errorf("The flags --run-post-install and --skip-post-install can't be both set at the same time.")
63+
os.Exit(errorcodes.ErrBadArgument)
64+
}
65+
if postInstallFlags.runPostInstall {
66+
logrus.Info("Will run post-install by user request")
67+
return false
68+
}
69+
if postInstallFlags.skipPostInstall {
70+
logrus.Info("Will skip post-install by user request")
71+
return true
72+
}
73+
74+
if !configuration.IsInteractive {
75+
logrus.Info("Not running from console, will skip post-install by default")
76+
return true
77+
}
78+
logrus.Info("Running from console, will run post-install by default")
79+
return false
80+
}
81+
5382
func runInstallCommand(cmd *cobra.Command, args []string) {
5483
inst, err := instance.CreateInstance()
5584
if err != nil {
@@ -71,7 +100,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
71100
PlatformPackage: platformRef.PackageName,
72101
Architecture: platformRef.Architecture,
73102
Version: platformRef.Version,
74-
SkipPostInstall: installFlags.skipPostInstall,
103+
SkipPostInstall: detectSkipPostInstallValue(),
75104
}
76105
_, err := core.PlatformInstall(context.Background(), platformInstallReq, output.ProgressBar(), output.TaskProgress())
77106
if err != nil {

Diff for: cli/core/upgrade.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,10 @@ func initUpgradeCommand() *cobra.Command {
4242
" " + os.Args[0] + " core upgrade arduino:samd",
4343
Run: runUpgradeCommand,
4444
}
45-
upgradeCommand.Flags().BoolVar(&upgradeFlags.skipPostInstall, "skip-post-install", false, "Do not run post-install scripts.")
45+
addPostInstallFlagsToCommand(upgradeCommand)
4646
return upgradeCommand
4747
}
4848

49-
var upgradeFlags struct {
50-
skipPostInstall bool
51-
}
52-
5349
func runUpgradeCommand(cmd *cobra.Command, args []string) {
5450
inst, err := instance.CreateInstance()
5551
if err != nil {
@@ -96,7 +92,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
9692
Instance: inst,
9793
PlatformPackage: platformRef.PackageName,
9894
Architecture: platformRef.Architecture,
99-
SkipPostInstall: upgradeFlags.skipPostInstall,
95+
SkipPostInstall: detectSkipPostInstallValue(),
10096
}
10197

10298
_, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress())

Diff for: configuration/term.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package configuration
17+
18+
import (
19+
"os"
20+
21+
"github.com/mattn/go-isatty"
22+
)
23+
24+
// IsInteractive is set to true if the CLI is interactive (it can receive inputs from terminal/console)
25+
var IsInteractive = isatty.IsTerminal(os.Stdin.Fd()) || isatty.IsCygwinTerminal(os.Stdin.Fd())
26+
27+
// HasConsole is set to true if the CLI outputs to a terminal/console
28+
var HasConsole = isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())

Diff for: go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ require (
2929
github.com/leonelquinteros/gotext v1.4.0
3030
github.com/marcinbor85/gohex v0.0.0-20200531163658-baab2527a9a2
3131
github.com/mattn/go-colorable v0.1.2
32-
github.com/mattn/go-runewidth v0.0.2 // indirect
32+
github.com/mattn/go-isatty v0.0.8
33+
github.com/mattn/go-runewidth v0.0.9 // indirect
3334
github.com/miekg/dns v1.0.5 // indirect
3435
github.com/oleksandr/bonjour v0.0.0-20160508152359-5dcf00d8b228 // indirect
3536
github.com/pkg/errors v0.9.1

Diff for: go.sum

+2-10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
55
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
66
github.com/GeertJohan/go.incremental v1.0.0 h1:7AH+pY1XUgQE4Y1HcXYaMqAI0m9yrFqo/jt0CW30vsg=
77
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
8-
github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voiMLQ=
9-
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
108
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
119
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
1210
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
@@ -132,8 +130,8 @@ github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx
132130
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
133131
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
134132
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
135-
github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC63o=
136-
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
133+
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
134+
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
137135
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
138136
github.com/mdlayher/genetlink v0.0.0-20190313224034-60417448a851/go.mod h1:EsbsAEUEs15qC1cosAwxgCWV0Qhd8TmkxnA9Kw1Vhl4=
139137
github.com/mdlayher/netlink v0.0.0-20190313131330-258ea9dff42c/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA=
@@ -144,8 +142,6 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
144142
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
145143
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
146144
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
147-
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229 h1:E2B8qYyeSgv5MXpmzZXRNp8IAQ4vjxIjhpAf5hv/tAg=
148-
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
149145
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
150146
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
151147
github.com/oleksandr/bonjour v0.0.0-20160508152359-5dcf00d8b228 h1:Cvfd2dOlXIPTeEkOT/h8PyK4phBngOM4at9/jlgy7d4=
@@ -197,10 +193,6 @@ github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
197193
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
198194
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
199195
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
200-
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
201-
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
202-
github.com/spf13/cobra v1.0.1-0.20200629195214-2c5a0d300f8b h1:grM+VdcoRu+xbzmCXM1KuH5UQGk9Lc8yCiwZZ2PKVdU=
203-
github.com/spf13/cobra v1.0.1-0.20200629195214-2c5a0d300f8b/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
204196
github.com/spf13/cobra v1.0.1-0.20200710201246-675ae5f5a98c h1:/dP/1GnfVIlWnB0YDImenSmneUCw3wjyq2RMgAG1e2o=
205197
github.com/spf13/cobra v1.0.1-0.20200710201246-675ae5f5a98c/go.mod h1:aeNIJzz/GSSVlS+gpCpQWZ83BKbsoW57mr90+YthtkQ=
206198
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=

0 commit comments

Comments
 (0)