Repository: fluxcd/flux2

Issue:
`flux create helmrelease`: Clarify that `--chart` cannot be used with OCIRepository
When combining `--chart-ref=OCIRepository` with the `--chart` flag, `flux create helmrelease` creates an invalid resource.

```
flux create helmrelease my-hr \
    --namespace=my-namespace \
    --chart-ref=OCIRepository/my-oci-repository.my-namespace \
    --chart my-chart \
    --export
```

Result:

```
---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: my-hr
  namespace: my-namespace
spec:
  chart:
    spec:
      chart: my-chart
      reconcileStrategy: ChartVersion
      sourceRef:
        name: ""
  interval: 1m0s
```

Applying this resource will result in an error message:

> ✗ HelmRelease.helm.toolkit.fluxcd.io "my-hr" is invalid: [spec.chart.spec.sourceRef.name: Invalid value: "": spec.chart.spec.sourceRef.name in body should be at least 1 chars long, spec.chart.spec.sourceRef.kind: Required value, <nil>: Invalid value: "null": some validation rules were not checked because the object was invalid; correct the existing errors to complete validation]

## Suggestion

The CLI should fail early with an error message indicating that `--chart` cannot be used in combination with `--chart-ref`.

Hints from issue comments:
@jaxels10: I have created a PR with a check to check if both `--chart` and `--chart-ref` are both set at the same time and return an error if that is the case:
[https://github.com/fluxcd/flux2/pull/5656](https://github.com/fluxcd/flux2/pull/5656)

Solution patch:
diff --git a/cmd/flux/create_helmrelease.go b/cmd/flux/create_helmrelease.go
index 2074502d..9a7e08cd 100644
--- a/cmd/flux/create_helmrelease.go
+++ b/cmd/flux/create_helmrelease.go
@@ -182,6 +182,10 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
 		return fmt.Errorf("chart or chart-ref is required")
 	}
 
+	if helmReleaseArgs.chart != "" && helmReleaseArgs.chartRef != "" {
+		return fmt.Errorf("cannot use --chart in combination with --chart-ref")
+	}
+
 	sourceLabels, err := parseLabels()
 	if err != nil {
 		return err



Test patch:
diff --git a/cmd/flux/create_helmrelease_test.go b/cmd/flux/create_helmrelease_test.go
index ffdef081..b9997977 100644
--- a/cmd/flux/create_helmrelease_test.go
+++ b/cmd/flux/create_helmrelease_test.go
@@ -42,6 +42,11 @@ func TestCreateHelmRelease(t *testing.T) {
 			args:   "create helmrelease podinfo --export",
 			assert: assertError("chart or chart-ref is required"),
 		},
+		{
+			name:   "chart and chartRef used in combination",
+			args:   "create helmrelease podinfo --chart podinfo --chart-ref foobar/podinfo --export",
+			assert: assertError("cannot use --chart in combination with --chart-ref"),
+		},
 		{
 			name:   "unknown source kind",
 			args:   "create helmrelease podinfo --source foobar/podinfo --chart podinfo --export",