From ae348c737f10d1ff8cdbfb027be91e338c1ea811 Mon Sep 17 00:00:00 2001 From: Vasubabu <3358152+vasubabu@users.noreply.github.com> Date: Wed, 29 Nov 2023 23:16:07 +0530 Subject: [PATCH] fix: deprecated promptui library --- go.mod | 10 +++++--- go.sum | 43 ++++++++++++++++++++++++-------- internal/devices/delete.go | 42 +++++++++---------------------- internal/gateway/delete.go | 19 +++++++------- internal/organizations/delete.go | 20 ++++++++------- internal/ports/convert.go | 18 +++++++------ internal/projects/delete.go | 21 +++++++++------- internal/ssh/delete.go | 20 ++++++++------- internal/vlan/delete.go | 17 +++++++------ internal/vrf/delete.go | 17 +++++++------ 10 files changed, 123 insertions(+), 104 deletions(-) diff --git a/go.mod b/go.mod index 08def837..8d6de149 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/equinix/metal-cli go 1.19 require ( + github.com/c-bata/go-prompt v0.2.6 github.com/equinix-labs/metal-go v0.26.0 - github.com/manifoldco/promptui v0.9.0 github.com/olekukonko/tablewriter v0.0.5 github.com/packethost/packngo v0.30.0 github.com/pkg/errors v0.9.1 @@ -17,17 +17,21 @@ require ( ) require ( - github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/magiconair/properties v1.8.7 // indirect - github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/mattn/go-tty v0.0.5 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/pkg/term v1.2.0-beta.2 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/rivo/uniseg v0.4.4 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.3.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect diff --git a/go.sum b/go.sum index 77c7f9bb..c690a953 100644 --- a/go.sum +++ b/go.sum @@ -38,12 +38,11 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/c-bata/go-prompt v0.2.6 h1:POP+nrHE+DfLYx370bedwNhsqmpCUynWPxuHi0C5vZI= +github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= @@ -146,10 +145,24 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= -github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= -github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0= +github.com/mattn/go-tty v0.0.5 h1:s09uXI7yDbXzzTTfw3zonKFzwGkyYlgU3OMjqA0ddz4= +github.com/mattn/go-tty v0.0.5/go.mod h1:u5GGXBtZU6RQoKV8gY5W6UhMudbR5vXnUe7j3pxse28= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= @@ -162,10 +175,15 @@ github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdU github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= +github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw= +github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= @@ -310,8 +328,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -320,9 +338,12 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -336,6 +357,8 @@ golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -345,14 +368,12 @@ golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8= -golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/internal/devices/delete.go b/internal/devices/delete.go index 1ca13632..0cf13522 100644 --- a/internal/devices/delete.go +++ b/internal/devices/delete.go @@ -1,36 +1,17 @@ -// Copyright © 2018 Jasmin Gacic -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - package devices import ( "context" "fmt" - "github.com/manifoldco/promptui" + "github.com/c-bata/go-prompt" "github.com/spf13/cobra" ) func (c *Client) Delete() *cobra.Command { var deviceID string var force bool + deleteDevice := func(id string) error { _, err := c.Service.DeleteDevice(context.Background(), id).ForceDelete(force).Execute() if err != nil { @@ -39,6 +20,7 @@ func (c *Client) Delete() *cobra.Command { fmt.Println("Device deletion initiated. Please check 'metal device get -i", deviceID, "' for status") return nil } + deleteDeviceCmd := &cobra.Command{ Use: `delete -i [-f]`, Short: "Deletes a device.", @@ -50,22 +32,22 @@ func (c *Client) Delete() *cobra.Command { # Deletes a VLAN, skipping confirmation: metal device delete -f -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277`, - RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete device %s: ", deviceID), - IsConfirm: true, - } - - _, err := prompt.Run() - if err != nil { + fmt.Printf("Are you sure you want to delete device %s (y/N): ", deviceID) + userInput := prompt.Input(">", func(d prompt.Document) []prompt.Suggest { + return []prompt.Suggest{ + {Text: "y", Description: "Yes"}, + {Text: "n", Description: "No"}, + } + }) + if userInput != "y" && userInput != "Y" { return nil } } if err := deleteDevice(deviceID); err != nil { - return fmt.Errorf("Could not delete Device: %w", err) + return fmt.Errorf("could not delete Device: %w", err) } return nil }, diff --git a/internal/gateway/delete.go b/internal/gateway/delete.go index 6d5bd7a3..fe2e9df7 100644 --- a/internal/gateway/delete.go +++ b/internal/gateway/delete.go @@ -24,7 +24,7 @@ import ( "context" "fmt" - "github.com/manifoldco/promptui" + "github.com/c-bata/go-prompt" "github.com/spf13/cobra" ) @@ -65,18 +65,19 @@ func (c *Client) Delete() *cobra.Command { cmd.SilenceUsage = true if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete Metal Gateway %s", gwayID), - IsConfirm: true, - } - - _, err := prompt.Run() - if err != nil { + fmt.Printf("Are you sure you want to delete device %s (y/N): ", gwayID) + userInput := prompt.Input(">", func(d prompt.Document) []prompt.Suggest { + return []prompt.Suggest{ + {Text: "y", Description: "Yes"}, + {Text: "n", Description: "No"}, + } + }) + if userInput != "y" && userInput != "Y" { return nil } } if err := deleteGway(gwayID); err != nil { - return fmt.Errorf("Could not delete Metal Gateway: %w", err) + return fmt.Errorf("could not delete Metal Gateway: %w", err) } return nil }, diff --git a/internal/organizations/delete.go b/internal/organizations/delete.go index aef4e3bd..c43aa70c 100644 --- a/internal/organizations/delete.go +++ b/internal/organizations/delete.go @@ -24,7 +24,7 @@ import ( "context" "fmt" - "github.com/manifoldco/promptui" + "github.com/c-bata/go-prompt" "github.com/spf13/cobra" ) @@ -58,19 +58,21 @@ func (c *Client) Delete() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true - if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete organization %s: ", organizationID), - IsConfirm: true, - } - _, err := prompt.Run() - if err != nil { + if !force { + fmt.Printf("Are you sure you want to delete device %s (y/N): ", organizationID) + userInput := prompt.Input(">", func(d prompt.Document) []prompt.Suggest { + return []prompt.Suggest{ + {Text: "y", Description: "Yes"}, + {Text: "n", Description: "No"}, + } + }) + if userInput != "y" && userInput != "Y" { return nil } } if err := deleteOrganization(organizationID); err != nil { - return fmt.Errorf("Could not delete Organization: %w", err) + return fmt.Errorf("could not delete Organization: %w", err) } return nil }, diff --git a/internal/ports/convert.go b/internal/ports/convert.go index ade72812..14570d6e 100644 --- a/internal/ports/convert.go +++ b/internal/ports/convert.go @@ -27,8 +27,8 @@ import ( "net/http" "strconv" + "github.com/c-bata/go-prompt" metal "github.com/equinix-labs/metal-go/metal/v1" - "github.com/manifoldco/promptui" "github.com/spf13/cobra" ) @@ -62,14 +62,16 @@ func (c *Client) Convert() *cobra.Command { } convToL2 := func(portID string) (*metal.Port, *http.Response, error) { - if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to convert Port %s to Layer2 and remove assigned IP addresses: ", portID), - IsConfirm: true, - } - _, err := prompt.Run() - if err != nil { + if !force { + fmt.Printf("Are you sure you want to convert Port %s to Layer2 and remove assigned IP addresses? (y/N): ", portID) + confirmation := prompt.Input(">>> ", func(d prompt.Document) []prompt.Suggest { + return []prompt.Suggest{ + {Text: "y", Description: "Yes"}, + {Text: "n", Description: "No"}, + } + }) + if confirmation != "y" && confirmation != "Y" { return nil, nil, nil } } diff --git a/internal/projects/delete.go b/internal/projects/delete.go index f05c90de..37a16556 100644 --- a/internal/projects/delete.go +++ b/internal/projects/delete.go @@ -24,7 +24,7 @@ import ( "context" "fmt" - "github.com/manifoldco/promptui" + "github.com/c-bata/go-prompt" "github.com/spf13/cobra" ) @@ -56,19 +56,22 @@ func (c *Client) Delete() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true - if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete project %s: ", projectID), - IsConfirm: true, - } - _, err := prompt.Run() - if err != nil { + if !force { + fmt.Printf("Are you sure you want to delete device %s (y/N): ", projectID) + userInput := prompt.Input(">", func(d prompt.Document) []prompt.Suggest { + return []prompt.Suggest{ + {Text: "y", Description: "Yes"}, + {Text: "n", Description: "No"}, + } + }) + if userInput != "y" && userInput != "Y" { return nil } } + if err := deleteProject(projectID); err != nil { - return fmt.Errorf("Could not delete Project: %w", err) + return fmt.Errorf("could not delete Project: %w", err) } return nil }, diff --git a/internal/ssh/delete.go b/internal/ssh/delete.go index f19de5aa..99bfeb24 100644 --- a/internal/ssh/delete.go +++ b/internal/ssh/delete.go @@ -24,7 +24,7 @@ import ( "context" "fmt" - "github.com/manifoldco/promptui" + "github.com/c-bata/go-prompt" "github.com/spf13/cobra" ) @@ -56,20 +56,22 @@ func (c *Client) Delete() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true - if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete SSH Key %s: ", sshKeyID), - IsConfirm: true, - } - _, err := prompt.Run() - if err != nil { + if !force { + fmt.Printf("Are you sure you want to delete device %s (y/N): ", sshKeyID) + userInput := prompt.Input(">", func(d prompt.Document) []prompt.Suggest { + return []prompt.Suggest{ + {Text: "y", Description: "Yes"}, + {Text: "n", Description: "No"}, + } + }) + if userInput != "y" && userInput != "Y" { return nil } } if err := deleteSSHKey(sshKeyID); err != nil { - return fmt.Errorf("Could not delete SSH Key: %w", err) + return fmt.Errorf("could not delete SSH Key: %w", err) } return nil }, diff --git a/internal/vlan/delete.go b/internal/vlan/delete.go index e975a6ea..5b2c34ce 100644 --- a/internal/vlan/delete.go +++ b/internal/vlan/delete.go @@ -24,7 +24,7 @@ import ( "context" "fmt" - "github.com/manifoldco/promptui" + "github.com/c-bata/go-prompt" "github.com/spf13/cobra" ) @@ -60,13 +60,14 @@ func (c *Client) Delete() *cobra.Command { cmd.SilenceUsage = true if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete virtual network %s", vnetID), - IsConfirm: true, - } - - _, err := prompt.Run() - if err != nil { + fmt.Printf("Are you sure you want to delete device %s (y/N): ", vnetID) + userInput := prompt.Input(">", func(d prompt.Document) []prompt.Suggest { + return []prompt.Suggest{ + {Text: "y", Description: "Yes"}, + {Text: "n", Description: "No"}, + } + }) + if userInput != "y" && userInput != "Y" { return nil } } diff --git a/internal/vrf/delete.go b/internal/vrf/delete.go index 9d39eb45..ee5bee5e 100644 --- a/internal/vrf/delete.go +++ b/internal/vrf/delete.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/manifoldco/promptui" + "github.com/c-bata/go-prompt" "github.com/spf13/cobra" ) @@ -39,13 +39,14 @@ func (c *Client) Delete() *cobra.Command { cmd.SilenceUsage = true if !force { - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Are you sure you want to delete VRF %s: ", vrfID), - IsConfirm: true, - } - - result, err := prompt.Run() - if err != nil || result != "y" { + fmt.Printf("Are you sure you want to delete device %s (y/N): ", vrfID) + userInput := prompt.Input(">", func(d prompt.Document) []prompt.Suggest { + return []prompt.Suggest{ + {Text: "y", Description: "Yes"}, + {Text: "n", Description: "No"}, + } + }) + if userInput != "y" && userInput != "Y" { return nil } }