From d9dfbf044e4f73b8e8bdcefbeb6e7aaf18b12437 Mon Sep 17 00:00:00 2001 From: Neil Garb Date: Wed, 23 Oct 2024 08:47:31 +0200 Subject: [PATCH] Add NoApp() --- app.go | 7 +++++++ app_test.go | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/app.go b/app.go index a39c88b..d23589d 100644 --- a/app.go +++ b/app.go @@ -393,3 +393,10 @@ func handleShutdownErr(a *App, ac AppContext, err error) error { } return err } + +// NoApp returns a nil app. +// It can be used when you call a function that accepts a *App, but there's no lu app in scope. +// f(lu.NoApp()) reads more clearly than f(nil). +func NoApp() *App { + return nil +} diff --git a/app_test.go b/app_test.go index b632b5d..8ad672d 100644 --- a/app_test.go +++ b/app_test.go @@ -370,3 +370,7 @@ func TestWaitFor(t *testing.T) { }) } } + +func TestNoApp(t *testing.T) { + require.Nil(t, lu.NoApp()) +}