format

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Copyright 2025 PRAS

Index

Constants

This section is empty.

Variables

View Source
var FormatCmd = &cobra.Command{
	Use:   "format",
	Short: "Prettify QML files",
	Long:  "Automatically format QML source files to ensure consistent style and readability.",
	Run: func(cmd *cobra.Command, args []string) {
		if !utilsIsValidPlasmoid() {
			fmt.Println(color.RedString("Current directory is not a valid plasmoid."))
			return
		}
		if !utilsIsPackageInstalled(consts.QmlFormatPackageName["binary"]) {
			pm, _ := utilsDetectPackageManager()
			var confirm bool
			confirmPrompt := &survey.Confirm{
				Message: "qmlformat is not installed. Do you want to install it?",
				Default: true,
			}
			if err := surveyAskOne(confirmPrompt, &confirm); err != nil {
				return
			}

			if confirm {
				if err := utilsInstallPackage(pm, consts.QmlFormatPackageName["binary"], consts.QmlFormatPackageName); err != nil {
					fmt.Println(color.RedString("Failed to install qmlformat."))
					return
				}
				fmt.Println(color.GreenString("qmlformat installed successfully."))
			} else {
				fmt.Println(color.YellowString("Operation cancelled."))
				return
			}
		}

		crrPath, _ := os.Getwd()
		relPath := filepath.Join(crrPath, dir)
		if watch {
			prettifyOnWatch(relPath, make(chan bool))
		} else {
			prettify(relPath)
		}
	},
}

FormatCmd represents the format command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL