@@ -23,7 +23,7 @@ import (
2323 "hpc-toolkit/pkg/config"
2424 "hpc-toolkit/pkg/modulewriter"
2525 "log"
26- "os "
26+ "path/filepath "
2727 "strings"
2828
2929 "github.com/spf13/cobra"
@@ -77,19 +77,27 @@ var (
7777
7878func runCreateCmd (cmd * cobra.Command , args []string ) {
7979 dc := expandOrDie (args [0 ])
80- if err := modulewriter .WriteDeployment (dc , outputDir , overwriteDeployment ); err != nil {
81- var target * modulewriter.OverwriteDeniedError
82- if errors .As (err , & target ) {
83- fmt .Printf ("\n %s\n " , err .Error ())
84- os .Exit (1 )
85- } else {
86- log .Fatal (err )
87- }
88- }
80+ deplName , err := dc .Config .DeploymentName ()
81+ cobra .CheckErr (err )
82+ deplDir := filepath .Join (outputDir , deplName )
83+ cobra .CheckErr (modulewriter .WriteDeployment (dc , deplDir , overwriteDeployment ))
84+
85+ fmt .Println ("To deploy your infrastructure please run:" )
86+ fmt .Println ()
87+ fmt .Printf ("./ghpc deploy %s\n " , deplDir )
88+ fmt .Println ()
89+ printAdvancedInstructionsMessage (deplDir )
90+ }
91+
92+ func printAdvancedInstructionsMessage (deplDir string ) {
93+ fmt .Println ("Find instructions for cleanly destroying infrastructure and advanced manual" )
94+ fmt .Println ("deployment instructions at:" )
95+ fmt .Println ()
96+ fmt .Printf ("%s\n " , modulewriter .InstructionsPath (deplDir ))
8997}
9098
9199func expandOrDie (path string ) config.DeploymentConfig {
92- dc , err := config .NewDeploymentConfig (path )
100+ dc , ctx , err := config .NewDeploymentConfig (path )
93101 if err != nil {
94102 log .Fatal (err )
95103 }
@@ -113,12 +121,30 @@ func expandOrDie(path string) config.DeploymentConfig {
113121
114122 // Expand the blueprint
115123 if err := dc .ExpandConfig (); err != nil {
116- log .Fatal (err )
124+ log .Fatal (renderError ( err , ctx ) )
117125 }
118126
119127 return dc
120128}
121129
130+ func renderError (err error , ctx config.YamlCtx ) string {
131+ var be config.BpError
132+ if errors .As (err , & be ) {
133+ if pos , ok := ctx .Pos (be .Path ); ok {
134+ return renderRichError (be .Err , pos , ctx )
135+ }
136+ }
137+ return err .Error ()
138+ }
139+
140+ func renderRichError (err error , pos config.Pos , ctx config.YamlCtx ) string {
141+ return fmt .Sprintf (`
142+ Error: %s
143+ on line %d, column %d:
144+ %d: %s
145+ ` , err , pos .Line , pos .Column , pos .Line , ctx .Lines [pos .Line - 1 ])
146+ }
147+
122148func setCLIVariables (bp * config.Blueprint , s []string ) error {
123149 for _ , cliVar := range s {
124150 arr := strings .SplitN (cliVar , "=" , 2 )
0 commit comments