Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse assumes syntax #383

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions assumes/expression.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2021 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.

package assumes

import "github.com/juju/version/v2"

var (
_ Expression = (*FeatureExpression)(nil)
_ Expression = (*CompositeExpression)(nil)
)

// ExpressionType represents the type of an assumes expression.
type ExpressionType string

const (
AnyOfExpression ExpressionType = "any-of"
AllOfExpression ExpressionType = "all-of"
)

// Expression is an interface implemented by all expression types in this package.
type Expression interface {
Type() ExpressionType
}

// VersionConstraint describes a constraint for required feature versions.
type VersionConstraint string

const (
VersionGTE VersionConstraint = ">="
VersionLT VersionConstraint = "<"
)

// FeatureExpression describes a feature that is required by the charm in order
// to be successfully deployed. Feature expressions may additionally specify a
// version constraint.
type FeatureExpression struct {
// The name of the feature.
Name string

// A feature within an assumes block may optionally specify a version
// constraint.
Constraint VersionConstraint
Version *version.Number

// The raw, unprocessed version string for serialization purposes.
rawVersion string
}

// Type implements Expression.
func (FeatureExpression) Type() ExpressionType { return ExpressionType("feature") }

// CompositeExpression describes a composite expression that applies some
// operator to a sub-expression list.
type CompositeExpression struct {
ExprType ExpressionType
SubExpressions []Expression
}

// Type implements Expression.
func (expr CompositeExpression) Type() ExpressionType { return expr.ExprType }
14 changes: 14 additions & 0 deletions assumes/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2021 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.

package assumes

import (
stdtesting "testing"

gc "gopkg.in/check.v1"
)

func Test(t *stdtesting.T) {
gc.TestingT(t)
}
Loading