commands API

commands

package

API reference for the commands package.

F
function

NewBuildCommand

NewBuildCommand returns the build command.

Returns

cmd/rfw/commands/build.go:9-17
func NewBuildCommand() *command.Command

{
	cmd := &command.Command{
		Name:        "build",
		Usage:       "build",
		Description: "Build the current project",
		Run:         runBuild,
	}
	return cmd
}
F
function

runBuild

Parameters

_
[]string

Returns

error
cmd/rfw/commands/build.go:19-25
func runBuild(cmd *command.Command, _ *command.RootFlags, _ []string) error

{
	if err := build.Build(); err != nil {
		return err
	}
	cmd.Logger.Success("Build completed")
	return nil
}
F
function

TestReadPortFromManifest

TestReadPortFromManifest verifies that readPortFromManifest reads the port
value from rfw.json when present and falls back to an empty string when the
file is missing or malformed.

Parameters

cmd/rfw/commands/commands_test.go:12-45
func TestReadPortFromManifest(t *testing.T)

{
	origWD, err := os.Getwd()
	if err != nil {
		t.Fatalf("getwd: %v", err)
	}
	t.Cleanup(func() { _ = os.Chdir(origWD) })

	dir := t.TempDir()
	if err := os.Chdir(dir); err != nil {
		t.Fatalf("chdir: %v", err)
	}

	// Missing file should return empty string.
	if got := readPortFromManifest(); got != "" {
		t.Fatalf("expected empty string, got %q", got)
	}

	// Create manifest with a port value.
	data := []byte(`{"port": 9090}`)
	if err := os.WriteFile(filepath.Join(dir, "rfw.json"), data, 0o644); err != nil {
		t.Fatalf("write rfw.json: %v", err)
	}
	if got := readPortFromManifest(); got != "9090" {
		t.Fatalf("expected 9090, got %q", got)
	}

	// Zero port should return empty string.
	if err := os.WriteFile("rfw.json", []byte(`{"port":0}`), 0o644); err != nil {
		t.Fatalf("rewrite rfw.json: %v", err)
	}
	if got := readPortFromManifest(); got != "" {
		t.Fatalf("expected empty string for zero port, got %q", got)
	}
}
F
function

NewDevCommand

NewDevCommand returns the dev command.

Returns

cmd/rfw/commands/dev.go:13-23
func NewDevCommand() *command.Command

{
	cmd := &command.Command{
		Name:        "dev",
		Usage:       "dev [--port <port>] [--host]",
		Description: "Start the development server",
		Run:         runDev,
	}
	cmd.AddFlag("port", "p", "Port to serve on", "", true)
	cmd.AddBoolFlag("host", "", "Expose the server to the network", false, false)
	return cmd
}
F
function

runDev

Parameters

_
[]string

Returns

error
cmd/rfw/commands/dev.go:25-40
func runDev(cmd *command.Command, _ *command.RootFlags, _ []string) error

{
	port := os.Getenv("RFW_PORT")
	if port == "" {
		port = cmd.GetFlagString("port")
		if port == "" {
			port = readPortFromManifest()
			if port == "" {
				port = "8080"
			}
		}
	}
	host := cmd.GetFlagBool("host")
	os.Setenv("RFW_DEV_BUILD", "1")
	srv := server.NewServer(port, host)
	return srv.Start()
}
F
function

readPortFromManifest

Returns

string
cmd/rfw/commands/dev.go:42-57
func readPortFromManifest() string

{
	var manifest struct {
		Port int `json:"port"`
	}
	data, err := os.ReadFile("rfw.json")
	if err != nil {
		return ""
	}
	if err := json.Unmarshal(data, &manifest); err != nil {
		return ""
	}
	if manifest.Port == 0 {
		return ""
	}
	return strconv.Itoa(manifest.Port)
}
F
function

NewInitCommand

NewInitCommand returns the init command.

Returns

cmd/rfw/commands/init.go:11-20
func NewInitCommand() *command.Command

{
	cmd := &command.Command{
		Name:        "init",
		Usage:       "init <project-name>",
		Description: "Initialize a new rfw project",
		Run:         runInit,
	}
	cmd.AddBoolFlag("skip-tidy", "", "Skip running go mod tidy", false, false)
	return cmd
}
F
function

runInit

Parameters

args
[]string

Returns

error
cmd/rfw/commands/init.go:22-33
func runInit(cmd *command.Command, _ *command.RootFlags, args []string) error

{
	if len(args) < 1 {
		return fmt.Errorf("please specify a project name")
	}
	projectName := args[0]
	skipTidy := cmd.GetFlagBool("skip-tidy")
	if err := initproj.InitProject(projectName, skipTidy); err != nil {
		return err
	}
	cmd.Logger.Success("Project initialized")
	return nil
}