func (c *Client) AddLocalCharm(curl *charm.URL, ch charm.Charm, force bool) (*charm.URL, error) {
	if curl.Schema != "local" {
		return nil, errors.Errorf("expected charm URL with local: schema, got %q", curl.String())
	}

	if err := c.validateCharmVersion(ch); err != nil {
		return nil, errors.Trace(err)
	}
	if err := lxdprofile.ValidateLXDProfile(lxdCharmProfiler{Charm: ch}); err != nil {
		if !force {
			return nil, errors.Trace(err)
		}
	}

	// Package the charm for uploading.
	var archive *os.File
	switch ch := ch.(type) {
	case *charm.CharmDir:
		var err error
		if archive, err = ioutil.TempFile("", "charm"); err != nil {
			return nil, errors.Annotate(err, "cannot create temp file")
		}
		defer os.Remove(archive.Name())
		defer archive.Close()
		if err := ch.ArchiveTo(archive); err != nil {
			return nil, errors.Annotate(err, "cannot repackage charm")
		}
		if _, err := archive.Seek(0, 0); err != nil {
			return nil, errors.Annotate(err, "cannot rewind packaged charm")
		}
	case *charm.CharmArchive:
		var err error
		if archive, err = os.Open(ch.Path); err != nil {
			return nil, errors.Annotate(err, "cannot read charm archive")
		}
		defer archive.Close()
	default:
		return nil, errors.Errorf("unknown charm type %T", ch)
	}

	anyHooksOrDispatch, err := hasHooksOrDispatch(archive.Name())
	if err != nil {
		return nil, errors.Trace(err)
	}
	if !anyHooksOrDispatch {
		return nil, errors.Errorf("invalid charm %q: has no hooks nor dispatch file", curl.Name)
	}

	curl, err = c.UploadCharm(curl, archive)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return curl, nil
}
// AddLocalCharm prepares the given charm with a local: schema in its
// URL, and uploads it via the API server, returning the assigned
// charm URL.
AddLocalCharm prepares the given charm with a local: schema in its
URL, and uploads it via the API server, returning the assigned
charm URL.
// AddLocalCharm prepares the given charm with a local : schema in its // URL and uploads it via the API server returning the assigned // charm URL .
func (c *Client) AddLocalCharm(curl *charm.URL, ch charm.Charm, force bool) (*charm.URL, error) {
	if curl.Schema != "local" {
		return nil, errors.Errorf("expected charm URL with local: schema, got %q", curl.String())
	}
	if err := c.validateCharmVersion(ch); err != nil {
		return nil, errors.Trace(err)
	}
	if err := lxdprofile.ValidateLXDProfile(lxdCharmProfiler{Charm: ch}); err != nil {
		if !force {
			return nil, errors.Trace(err)
		}
	}
	var archive *os.File
	switch ch := ch.(type) {
	case *charm.CharmDir:
		var err error
		if archive, err = ioutil.TempFile("", "charm"); err != nil {
			return nil, errors.Annotate(err, "cannot create temp file")
		}
		defer os.Remove(archive.Name())
		defer archive.Close()
		if err := ch.ArchiveTo(archive); err != nil {
			return nil, errors.Annotate(err, "cannot repackage charm")
		}
		if _, err := archive.Seek(0, 0); err != nil {
			return nil, errors.Annotate(err, "cannot rewind packaged charm")
		}
	case *charm.CharmArchive:
		var err error
		if archive, err = os.Open(ch.Path); err != nil {
			return nil, errors.Annotate(err, "cannot read charm archive")
		}
		defer archive.Close()
	default:
		return nil, errors.Errorf("unknown charm type %T", ch)
	}
	anyHooksOrDispatch, err := hasHooksOrDispatch(archive.Name())
	if err != nil {
		return nil, errors.Trace(err)
	}
	if !anyHooksOrDispatch {
		return nil, errors.Errorf("invalid charm %q: has no hooks nor dispatch file", curl.Name)
	}
	curl, err = c.UploadCharm(curl, archive)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return curl, nil
}
func ( c * Client ) AddLocalCharm ( curl * charm . URL , ch charm . Charm , force bool ) ( * charm . URL , error ) { if curl . Schema != " " { return nil , errors . Errorf ( " " , curl . String ( ) ) } if err := c . validateCharmVersion ( ch ) ; err != nil { return nil , errors . Trace ( err ) } if err := lxdprofile . ValidateLXDProfile ( lxdCharmProfiler { Charm : ch } ) ; err != nil { if ! force { return nil , errors . Trace ( err ) } } var archive * os . File switch ch := ch . ( type ) { case * charm . CharmDir : var err error if archive , err = ioutil . TempFile ( " " , " " ) ; err != nil { return nil , errors . Annotate ( err , " " ) } defer os . Remove ( archive . Name ( ) ) defer archive . Close ( ) if err := ch . ArchiveTo ( archive ) ; err != nil { return nil , errors . Annotate ( err , " " ) } if _ , err := archive . Seek ( 0 , 0 ) ; err != nil { return nil , errors . Annotate ( err , " " ) } case * charm . CharmArchive : var err error if archive , err = os . Open ( ch . Path ) ; err != nil { return nil , errors . Annotate ( err , " " ) } defer archive . Close ( ) default : return nil , errors . Errorf ( " " , ch ) } anyHooksOrDispatch , err := hasHooksOrDispatch ( archive . Name ( ) ) if err != nil { return nil , errors . Trace ( err ) } if ! anyHooksOrDispatch { return nil , errors . Errorf ( " " , curl . Name ) } curl , err = c . UploadCharm ( curl , archive ) if err != nil { return nil , errors . Trace ( err ) } return curl , nil }
AddLocalCharm prepares the given charm with a local: schema in its
URL, and uploads it via the API server, returning the assigned
charm URL.
AddLocalCharm prepares the given charm with a local : schema in its URL and uploads it via the API server returning the assigned charm URL .
// Package the charm for uploading.