Skip to content

Commit 5469be9

Browse files
authored
changes how import/export of prebuilts functions (#86)
When importing and exporting prebuilts, the application would create a new key in the prebuilt called `filename`. This change effectively gets rid of that need and now just uses the `data` key. When the prebuilt as exported with `--expand`, the `data` key will now be prefaces with `@` to denote the data is in an external file which is consistent with the rest of the application.
1 parent c36a72e commit 5469be9

1 file changed

Lines changed: 29 additions & 19 deletions

File tree

internal/runners/prebuilts.go

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ func NewPrebuiltRunner(client client.Client, cfg *config.Config) *PrebuiltRunner
3434
}
3535
}
3636

37-
//////////////////////////////////////////////////////////////////////////////
38-
// Reader Interface
39-
//
37+
/*
38+
******************************************************************************
39+
Reader interface
40+
******************************************************************************
41+
*/
4042

4143
// Get implements the "get prebuilts ..." command
4244
func (r *PrebuiltRunner) Get(in Request) (*Response, error) {
@@ -77,9 +79,11 @@ func (r *PrebuiltRunner) Describe(in Request) (*Response, error) {
7779
), nil
7880
}
7981

80-
//////////////////////////////////////////////////////////////////////////////
81-
// Writer Interface
82-
//
82+
/*
83+
******************************************************************************
84+
Writer interface
85+
******************************************************************************
86+
*/
8387

8488
// Create implements the `create prebuilt ...` command
8589
func (r *PrebuiltRunner) Create(in Request) (*Response, error) {
@@ -235,9 +239,11 @@ func (r *PrebuiltRunner) Clear(in Request) (*Response, error) {
235239
return NewResponse(fmt.Sprintf("Deleted %v prebuilt(s)", cnt)), nil
236240
}
237241

238-
//////////////////////////////////////////////////////////////////////////////
239-
// Importer Interface
240-
//
242+
/*
243+
******************************************************************************
244+
Importer interface
245+
******************************************************************************
246+
*/
241247

242248
// Import implements the `import prebuilt ...` command
243249
func (r *PrebuiltRunner) Import(in Request) (*Response, error) {
@@ -267,8 +273,8 @@ func (r *PrebuiltRunner) Import(in Request) (*Response, error) {
267273
for _, ele := range mPkg["bundles"].([]interface{}) {
268274
item := ele.(map[string]interface{})
269275

270-
if _, exists := item["filename"]; exists {
271-
fp := filepath.Join(wd, item["filename"].(string))
276+
if strings.HasPrefix(item["data"].(string), "@") {
277+
fp := filepath.Join(wd, item["data"].(string)[1:])
272278

273279
var b map[string]interface{}
274280

@@ -308,9 +314,11 @@ func (r *PrebuiltRunner) Import(in Request) (*Response, error) {
308314

309315
}
310316

311-
//////////////////////////////////////////////////////////////////////////////
312-
// Exporter Interface
313-
//
317+
/*
318+
******************************************************************************
319+
Exporter interface
320+
******************************************************************************
321+
*/
314322

315323
// Export implements the `export prebuilt ...` command
316324
func (r *PrebuiltRunner) Export(in Request) (*Response, error) {
@@ -377,9 +385,11 @@ func (r *PrebuiltRunner) Export(in Request) (*Response, error) {
377385
), nil
378386
}
379387

380-
//////////////////////////////////////////////////////////////////////////////
381-
// Private functions
382-
//
388+
/*
389+
******************************************************************************
390+
Private functions
391+
******************************************************************************
392+
*/
383393

384394
func (r *PrebuiltRunner) validatePackage(in services.PrebuiltPackage) error {
385395
logger.Trace()
@@ -510,8 +520,8 @@ func (r *PrebuiltRunner) expandPrebuilt(pkg *services.PrebuiltPackage, path stri
510520
}
511521

512522
bundles = append(bundles, map[string]interface{}{
513-
"type": ele.Type,
514-
"filename": filepath.Join(fmt.Sprintf("bundles/%ss", ele.Type), fn),
523+
"type": ele.Type,
524+
"data": fmt.Sprintf("@%s", filepath.Join(fmt.Sprintf("bundles/%ss", ele.Type), fn)),
515525
})
516526
}
517527

0 commit comments

Comments
 (0)