github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/core/charm/format.go (about)

     1  // Copyright 2021 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package charm
     5  
     6  import "github.com/juju/charm/v12"
     7  
     8  // MetadataFormat of the parsed charm.
     9  type MetadataFormat int
    10  
    11  // MetadataFormat are the different versions of charm metadata supported.
    12  const (
    13  	FormatUnknown MetadataFormat = iota
    14  	FormatV1      MetadataFormat = iota
    15  	FormatV2      MetadataFormat = iota
    16  )
    17  
    18  // Format returns the metadata format for a given charm.
    19  func Format(ch charm.CharmMeta) MetadataFormat {
    20  	m := ch.Manifest()
    21  	if m == nil || len(m.Bases) == 0 || len(ch.Meta().Series) > 0 {
    22  		return FormatV1
    23  	}
    24  	return FormatV2
    25  }